问题
Code:
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();
}
}
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.
回答1:
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.
Go to the properties of your new timer (named "timer1" by default) and change:
- Enable to true
- Interval to 1000 milliseconds, i.e., one second
Double-click on the timer1
Timer component on your form designer (at the bottom). That will create a handler for the default event (Tick
).
Make that code look like:
private int _count = 0;
private void timer1_Tick(object sender, EventArgs e)
{
++_count;
Tlbl_Timer.Text = _count.ToString();
}
You should see your label start counting at 1 and going up until it overflows (somewhat north of two billion).
来源:https://stackoverflow.com/questions/53770432/windows-form-doesnt-show-c-sharp-timer