지금 C#으로 캘린더를 프로그래밍하고 있습니다. 캘린더를 호출하면 현재 달의 일수만큼 패널을 생성합니다. 그러나 현재 월을 1 씩 늘리려면이 달의 패널이 거기에 쌓여 있습니다. 그래서 월을 변경하자 마자 모든 패널을 삭제해야합니다. 하지만이 경우 어떻게 할 수 있습니까?내 캘린더에서 모든 패널을 삭제하려면 어떻게해야합니까?
도움 주셔서 감사합니다.
코드 eplain : 먼저 createPanel 메소드를 호출하여 당월 패널을 작성합니다. 다음으로 MonthAdd 메서드를 클릭하면 만든 모든 패널을 삭제하려고합니다. 내가 당신을 잘 undestood하지만 내 마음에 오는 첫번째 간단한 solutiona 경우
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Globalization;
namespace Einteilungs_Plan
{
public partial class Kalender : Form
{
public DateTime TodayDate { get; set; }
int counting = 0;
public Kalender()
{
InitializeComponent();
//Kalenderwochen initialisieren
monat(counting);
createPanel(true);
}
public string monat(int adding)
{
string monat = DateTime.Now.AddMonths(adding).ToString("MMMM");
tbMonat.Text = monat;
return monat;
}
private void btnAddMonth_Click(object sender, EventArgs e)
{
counting++;
if(counting < 12)
{
monat(counting);
switch (counting)
{
case 0:
int number = 10;
break;
case 1:
break;
default:
break;
}
}
else
{
counting--;
}
}
private void btnRemoveMonth_Click(object sender, EventArgs e)
{
counting--;
if (counting > -1)
{
monat(counting);
}
else
{
counting++;
}
}
public void createPanel(bool remove)
{
var numDays = DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month);
int locationX = 12;
int locationY = 74;
for (int i = 0; i <= numDays; i++)
{
//Create Panel
Panel test = new Panel();
//Fill Panel
test.Name = "panel" + i;
test.Width = 200;
test.Height = 100;
test.BackColor = Color.White;
test.Location = new System.Drawing.Point(locationX, locationY);
this.Controls.Add(test);
test.Show();
if(i == 6 || i == 13 || i == 20 || i == 28)
{
locationY += 106;
locationX = -194;
}
locationX += 206;
}
}
public void Kalender_Shown(object sender, EventArgs e)
{
}
private void Kalender_Load(object sender, EventArgs e)
{
}
private void btnNeuerEintrag_Click(object sender, EventArgs e)
{
Formular formular = new Formular();
formular.Show();
formular.Focus();
}
private void btnHinzufügen_Click(object sender, EventArgs e)
{
Formular formular = new Formular();
formular.Show();
formular.Focus();
}
}
}
createPanel 메서드 xD에서 bool 무시 xD 삭제하지 않았습니다 ... –