按下按钮时输入新文字 [英] New text when pressing a button
本文介绍了按下按钮时输入新文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,嗨!
我该怎么做以下事情:
我希望每次按i按钮时label1中的文本都发生变化.例如:
So, HI!
How do i do the following thing:
I want the text in label1 to change every time I press i button. For example:
String text = "hello", "elephant", "pig", "dog";
<pre>private void Button1_Click(object sender, EventArgs e)
{
Label1.Text = text;
}
所以我第一次按下按钮时会打招呼,下一次是大象,下一次是猪,最后一次是狗,然后又打招呼,等等...
先感谢您! :laugh:
so the first time that i press the button it shows hello, next time elephant, next time pig and the last time dog and then hello again etc...
Thank you in advance! :laugh:
推荐答案
String[] text = { "hello", "elephant", "pig", "dog" };
int count=0;
private void Button1_Click(object sender, EventArgs e)
{
Label1.Text=text[(count%text.Length)];
count++;
}
尝试类似的方法-
Try something like -
int count=0;
private void Button1_Click(object sender, EventArgs e)
{
if (count > text.Length)
{
count = 0;
}
Label1.Text = text[count++];
}
这篇关于按下按钮时输入新文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文