问题描述
我有这个代码,它只显示月份按钮,请告诉我我做的错误
使用系统;
使用System.Collections.Generic;
使用System.Drawing;
使用System.Drawing.Drawing2D;
使用System.Globalization;
使用System.Linq;
使用System.Windows.Forms;
名称空间Uis.Calendar
{
公共部分类ucCalander:UserControl
{
string [] weekDays = {Sun,Mon, Tue,Wed,Thu,Fri,Sat};
string [] MonthArray = {January,February,March,April, May,June,July,August,September,October,November,December};
string [] DayArray = {1 ,2,3,4,5,6,7,8,9,......};
public ucCalander()
{
InitializeComponent();
}
private void ucCalander_Load(object sender,EventArgs e)
{
CreateMonthButtons();
CreateDayButtons();
DisplayWeekDays();
}
#region按钮创建
private void CreateMonthButtons()
{
int lnRowMonth = 10;
int lnColMonth = 10;
for(int i = 0;我< 13; i ++)
{
MonthButton btnMonth = new MonthButton();
btnMonth.Location = new Point(lnRowMonth,lnColMonth);
btnMonth.Size = new Size(80,40);
btnMonth.Name =btnMonth+ i;
btnMonth.Text = MonthArray [i ];
btnMonth.BackColor = Color.Yellow;
btnMonth.Click + = new EventHandler(btnMonth_Click);
lnColMonth = lnColMonth + 40 ;
btnMonth.Tag = i.ToString();
this.Controls.Add(btnMonth);
}
}
private void CreateDayButtons()
{
int lnRowDay = 10;
int lnColDay = 10;
for(int i = 0; i< 13; i ++)
{
DayButtonbtnDay = new DayButton();
btnDay.Location = new Point(lnRowDay,lnColDay);
btnDay.Size = new Size(80,40);
btnDay.Name =btnDay+ i;
btnDay.Text = DayArray [i];
btnDay.BackColor = Color.Yellow;
btnDay.Click + = new EventHandler(btnDay_Click);
lnRowDay = lnRowDay + 70;
btnDay.Tag = i.ToString();
this.Controls.Add(btnDay);
}
}
private void DisplayWeekDays()
{
int lnRowLabel = 150;
int lnColLabel = 10;
for( int i = 0;我< 8; i ++)
{
Label lblWeekDays = new Label();
lblWeekDays.Location = new Point(lnRowLabel,lnColLabel);
lblWeekDays.Text = weekDays [i];
lblWeekDays.ForeColor = Color.Red;
lblWeekDays.Font = new Font(Arial,12 ,FontStyle.Bold);
lnRowLabel = lnRowLabel + 100;
lblWeekDays.Tag =(i + 12).ToString();
this.Controls.Add(lblWeekDays);
}
}
#endregion按钮创建
#region点击
private void btnMonth_Click(object sender,EventArgs e)
{
}
private void btnDay_Click(object sender,EventArgs e)
{
}
#endregion点击
}
}
提前感谢
I have this code, it shows only the month button, please show me the error I did
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
namespace Uis.Calendar
{
public partial class ucCalander : UserControl
{
string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
string[] MonthArray = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
string[] DayArray = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "..." };
public ucCalander()
{
InitializeComponent();
}
private void ucCalander_Load(object sender, EventArgs e)
{
CreateMonthButtons();
CreateDayButtons();
DisplayWeekDays();
}
# region Button Create
private void CreateMonthButtons()
{
int lnRowMonth = 10;
int lnColMonth = 10;
for (int i = 0; i < 13; i++)
{
MonthButton btnMonth = new MonthButton();
btnMonth.Location = new Point(lnRowMonth, lnColMonth);
btnMonth.Size = new Size(80, 40);
btnMonth.Name = "btnMonth" + i;
btnMonth.Text = MonthArray[i];
btnMonth.BackColor = Color.Yellow;
btnMonth.Click += new EventHandler(btnMonth_Click);
lnColMonth = lnColMonth + 40;
btnMonth.Tag = i.ToString();
this.Controls.Add(btnMonth);
}
}
private void CreateDayButtons()
{
int lnRowDay = 10;
int lnColDay = 10;
for (int i = 0; i < 13; i++)
{
DayButton btnDay = new DayButton();
btnDay.Location = new Point(lnRowDay, lnColDay);
btnDay.Size = new Size(80, 40);
btnDay.Name = "btnDay" + i;
btnDay.Text = DayArray[i];
btnDay.BackColor = Color.Yellow;
btnDay.Click += new EventHandler(btnDay_Click);
lnRowDay = lnRowDay + 70;
btnDay.Tag = i.ToString();
this.Controls.Add(btnDay);
}
}
private void DisplayWeekDays()
{
int lnRowLabel = 150;
int lnColLabel = 10;
for (int i = 0; i < 8; i++)
{
Label lblWeekDays = new Label();
lblWeekDays.Location = new Point(lnRowLabel, lnColLabel);
lblWeekDays.Text = weekDays[i];
lblWeekDays.ForeColor = Color.Red;
lblWeekDays.Font = new Font("Arial", 12, FontStyle.Bold);
lnRowLabel = lnRowLabel + 100;
lblWeekDays.Tag = (i + 12).ToString();
this.Controls.Add(lblWeekDays);
}
}
# endregion Button Create
# region Click
private void btnMonth_Click(object sender, EventArgs e)
{
}
private void btnDay_Click(object sender, EventArgs e)
{
}
# endregion Click
}
}
thanks in advance
这篇关于添加控件仅显示月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!