C#打印特定月份的日历正文 [英] c# print calendar body for a specific month
问题描述
你好,
我已经制作了一个日历,每个日期1,2 ..31是一个按钮.
日历默认返回当前月份.
我将所有内容都放在TableGridLayout中
但是当我想在单元格中打印日期时遇到了一个问题,因为我很困惑..!
Hello,
I have made a calendar, every date, 1,2 ..31 is a button.
The calendar returns the current month by default.
And I am putting everything in TableGridLayout
But I have a problem when i want to print dates inside the cells, as i got confused..!
Button[] buttons = new Button[numberOfDaysInMonth];
int day = firstDayAsNumber;//this is the first day of moneth, if it is 0
//then the first day will go to column 0
int row = 0;//this row must be 0 again after it fills the first row
for (int i = 0; i < buttons.Length; i++)
{
buttons[i] = new Button();
buttons[i].Name = "Button" + i.ToString();
buttons[i].Text = i.ToString();
table1.Controls.Add(buttons[i], day, 0); /*PROBLEM HERE!!??!*/
}
}
请帮助我
Please help me
推荐答案
我的猜测是,由于您未在增加或使用行变量(或
My guess is that you are trying to add multiple controls to the same cell in your layout as you are not incrementing or using the row variable (or the day variable for that matter).
for (int i = 0; i < buttons.Length; i++)
{
buttons[i] = new Button();
buttons[i].Name = "Button" + i.ToString();
buttons[i].Text = i.ToString();
table1.Controls.Add(buttons[i], day, row);
++day;
// MessageBox.Show("day now is after++" + day);
//MessageBox.Show("row now is " + row);
if (day == 6) {
day = 0;
}
if ((day) % 6 == 0) {
row++;
}
}
最后一个单元格为空,它像这样打印
就像星期六下的一切都是空的
我希望我能给你看p
周日周二周三周四周五周六
1 .... 2
3 ... 4 .... 5 ... 6 .... 7 .... 8
9 ..
为什么是那个???
the last cell is empty it prints like this
like everything under Sat is emptyutput
i wish i could show u the p
Sun Mon Tue Wed Thur Fri Sat
1 ....2
3...4....5...6....7....8
9..
why is that ???
这篇关于C#打印特定月份的日历正文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!