当按钮多次点击C#改变标签文本 [英] C# change label text when button clicked multiple times
本文介绍了当按钮多次点击C#改变标签文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对不起,我是新来这个只是想知道,如果有人可以帮助,我试图让我的标签,我点击按钮,每一次改变其文本。不知道我应该怎么去做。谁能帮我请。
私人无效的button1_Click(对象发件人,EventArgs五)
{
串[] MONTHNAME;
MONTHNAME =新的字符串[12];
MONTHNAME [0] =一月;
MONTHNAME [1] =二月;
MONTHNAME [2] =三八;
MONTHNAME [3] =四月;
MONTHNAME [4] =五一
MONTHNAME [5] =六一;
MONTHNAME [6] =七一;
MONTHNAME [7] =八一;
MONTHNAME [8] =九;
MONTHNAME [9] =十一;
MONTHNAME [10] =十一月;
MONTHNAME [11] =十二月;
label1.Text =(MONTHNAME [0]);
label1.Text =(MONTHNAME [1]);
解决方案
这应该做的伎俩:
声明在类中的数组和int
的String [] MONTHNAME = {一月,二月,月,月,月,君,月,月,月,月,月,月};
静态INT I = 0;
然后在点击按钮
保护无效btnAddMonth_Click(对象发件人,EventArgs五)
{
lblMonth.Text = MONTHNAME [I]
I =(I + 1)%12;
}
Sorry I am new to this just wondering if someone can help, I am trying to get my label to change its text every time I click the button. Not sure how I should go about it. Can anyone help me please.
private void button1_Click(object sender, EventArgs e)
{
string[] MonthName;
MonthName = new string[12];
MonthName[0] = "January";
MonthName[1] = "February";
MonthName[2] = "March";
MonthName[3] = "April";
MonthName[4] = "May";
MonthName[5] = "June";
MonthName[6] = "July";
MonthName[7] = "August";
MonthName[8] = "September";
MonthName[9] = "October";
MonthName[10] = "November";
MonthName[11] = "December";
label1.Text = (MonthName[0]);
label1.Text = (MonthName[1]);
解决方案
This should do the trick:
Declare the array and an int in the class
string[] MonthName = { "Jan", "Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" };
static int i = 0;
Then in the button click
protected void btnAddMonth_Click(object sender, EventArgs e)
{
lblMonth.Text = MonthName[i];
i = (i+1) % 12;
}
这篇关于当按钮多次点击C#改变标签文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文