Windows窗体不显示C#计时器 [英] Windows Form Doesn't Show C# Timer
问题描述
代码:
while ( int_Timer > 0 )
{
int int_Ticks = 0;
if ( int_Ticks < 100)
{
int_Ticks++;
}
if (int_Ticks == 100)
{
int_Timer--;
lbl_Timer.Text = int_Timer.ToString();
}
}
因此,我基本上尝试制作一个计时器,因为实现了此代码,所以表单没有出现在任务栏中.实际上,唯一的迹象就是正在运行Visual Studio调试.
So I basically tried to make a timer however, since I implemented this code the form doesn't appear in the taskbar. In fact the only indication is the Visual Studio Debug running.
推荐答案
进入Windows窗体工具箱.在组件"下,找到计时器".将其拖放到您的表单上.它不会显示在您放置它的位置(它是不可见的),但是会显示在下面的窗格中.
Go into the Windows Forms toolbox. Under "Component", find "Timer". Drag/drop one onto your form. It won't show up where you dropped it (it's non-visible), but it will show up in a pane below.
转到新计时器的属性(默认情况下命名为"timer1")并更改:
Go to the properties of your new timer (named "timer1" by default) and change:
- 启用 true
- 间隔 1000 毫秒,即一秒
- Enable to true
- Interval to 1000 milliseconds, i.e., one second
双击表单设计器上的timer1
Timer组件(在底部).这将为默认事件(Tick
)创建一个处理程序.
Double-click on the timer1
Timer component on your form designer (at the bottom). That will create a handler for the default event (Tick
).
使代码看起来像这样:
private int _count = 0;
private void timer1_Tick(object sender, EventArgs e)
{
++_count;
Tlbl_Timer.Text = _count.ToString();
}
您应该看到标签从1开始计数,一直到溢出为止(大约20亿).
You should see your label start counting at 1 and going up until it overflows (somewhat north of two billion).
这篇关于Windows窗体不显示C#计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!