vb.net 单击按钮时如何触发计时器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21561712/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:39:51  来源:igfitidea点击:

How to make a timer trigger when you click a button?

vb.netwinformsvisual-studio-2012timer

提问by user3271720

I am working on a Windows Form Application, making a button to show another form and I am trying to make the user wait some time after he clicks the button and after the time passes then the form will open.

我正在处理一个 Windows 窗体应用程序,制作一个按钮来显示另一个窗体,我试图让用户在单击按钮后等待一段时间,然后在时间过去后窗体将打开。

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Timer1.Start() 
End Sub 

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 
    Timer1.Stop() 
    Form3.Show() 
    Me.Hide() 
End Sub

When I use the code above, Form3is shown before I even click the button.

当我使用上面的代码时,Form3在我点击按钮之前就显示出来了。

回答by Steven Doggart

You need to make sure that you set the Enabledproperty on the Timer1component to Falsein the form designer.

您需要确保在表单设计器Enabled中将Timer1组件上的属性设置为False