[英]When event handler updates the content of a control? C#,WPF
I have this silly C# code on a buttonClick (WPF) handler and i wonder why the text box shows only the last value(=0) and no the previous values(9-1) . 我在buttonClick(WPF)处理程序上有这个愚蠢的C#代码,我不知道为什么文本框仅显示最后一个值(= 0)而没有显示以前的值(9-1)。 When I tested the code to a console application I saw all values in the command line.(I am beginner to C#,WPF) 当我在控制台应用程序上测试代码时,我在命令行中看到了所有值。(我是C#,WPF的初学者)
private void clock_Click(object sender, RoutedEventArgs e)
{
DateTime clicktime = DateTime.Now;
int nextsecont = DateTime.Now.Second + 1;
int now = clicktime.Second;
int timer = 10;
do
{
if (nextsecont == DateTime.Now.Second)
{
now++;
timer--;
nextsecont++;
textbox3.Text = timer.ToString();
}
} while (nextsecont <= (clicktime.Second + 10));
}
PS: I know there are better ways to do that (fe to use timer) but this is not the point. PS:我知道有更好的方法(例如使用计时器),但这不是重点。 Sorry for my english.. 对不起我的英语不好..
Explanation: now i see the initial value for 10 seconds and then i see the 0. I don't see intermediate values.. 说明:现在我看到初始值10秒钟,然后看到0。我没有看到中间值。
If you want all of the data to display in the textbox, you'll need to append the data to what is already in there. 如果您希望所有数据都显示在文本框中,则需要将数据附加到该文本框中。
textbox3.Text += " " + timer.ToString();
That will take what is in there, add a space, and then the timer. 那将占用其中的空间,添加一个空间,然后添加计时器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.