2015-10-20 149 views

回答

2

如何在按鈕單擊後禁用按鈕3秒並單獨啓用 按鈕?

最簡單的形式:

Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    Button1.Enabled = False 

    ' ... do something ... 

    Await Task.Delay(3000) 

    Button1.Enabled = True 
End Sub 

如果 「有所作爲」 部分耗時的話,也許更多的東西一樣:

Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    Button1.Enabled = False 

    Await Task.Run(Sub() 

         ' ... do something ... 

         System.Threading.Thread.Sleep(3000) 
        End Sub) 

    Button1.Enabled = True 
End Sub 
+0

非常感謝你Mike! – Foxseiz