添加控件仅显示月份 [英] Add control only shows months

查看:70
本文介绍了添加控件仅显示月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码,它只显示月份按钮,请告诉我我做的错误



使用系统;

使用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点击



}

}



提前感谢

解决方案

我可以看到所有按钮。由于位置设置错误,一些按钮会覆盖其他按钮

所有场景的for循环都有错误



  private   void  CreateMonthButtons()
{
int lnRowMonth = 10 ;
int lnColMonth = 10 ;

for int i = 0 ; i < 13 ; i ++) // 将其更改为i< 12
{





  private   void  CreateDayButtons()
{
int lnRowDay = 100 ; // 位置已更改
int lnColDay = 10 ;

for int i = 0 ; i < 13 ; i ++) // 将其更改为i< 10
{





  private   void  DisplayWeekDays()
{
int lnRowLabel = 100 ; // 位置已更改
int lnColLabel = 50 ; // 位置已更改

for int i = 0 ; i < 8 ; i ++) // 将它更改为i< 7
{





如果位置和循环发生变化,我可以看到所有按钮


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

解决方案

I can see all buttons. Some buttons override other buttons due to position set error.
There is error in for loop for all scenario

private void CreateMonthButtons()
{
int lnRowMonth = 10;
int lnColMonth = 10;
 
for (int i = 0; i < 13; i++) // change it to i<12
{



private void CreateDayButtons()
{
int lnRowDay = 100; //position changed
int lnColDay = 10;
 
for (int i = 0; i < 13; i++) // change it to i<10
{



private void DisplayWeekDays()
{
int lnRowLabel = 100; //position changed
int lnColLabel = 50; //position changed
 
for (int i = 0; i < 8; i++) // change it to i<7
{



I can see all buttons if position and loop changed


这篇关于添加控件仅显示月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆