简体   繁体   English

Visual Studio 按钮事件

[英]Visual Studio Button Event

I would like to code a button that after 3 clicks, links the user to my site.我想编写一个按钮,点击 3 次后,将用户链接到我的网站。 The first 2 should generate a code in the textbox and the last one should then link them.前两个应该在文本框中生成一个代码,最后一个应该链接它们。 This is what i have so far这是我到目前为止

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    ProgressBar1.Increment(3)
    If ProgressBar1.Value = 100 Then
        TextBox1.Text = "Thank you"
        Timer1.Stop()
    End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If RadioButton1.Checked = True Then
        Timer1.Start()
    ElseIf RadioButton2.checked = True Then
        Timer1.Start()
    Else
        TextBox1.Text = "Please Select Option"
    End If
End Sub

I dont know what is the use of ProgressBar and Timer.不知道ProgressBar和Timer有什么用。 But if you wan to know how many times user has click on a button, a counter variable should do.但是如果你想知道用户点击了多少次按钮,计数器变量应该可以。

Private _clickCounter As Integer

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    _clickCounter += 1

    If _clickCounter = 3 Then
        MsgBox("3 times")
        _clickCounter = 0
        'link to your site
    Else
        'generate code in textbox
    End If
End Sub

Use an integer that increases each time the button is clicked and a Select Case statement to detect that;使用每次单击按钮时增加的整数和Select Case语句来检测;

Dim NumberOfClicks As Integer = 0

Dim webAddress As String = "http://www.YourWebsite.com/"

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
 number = number + 1
 Select Case number
      Case 1
          ''''' Code for your textbox
      Case 2
          ''''' Code for your textbox
      Case 3
           Process.Start(webAddress)
End Sub

This should do.这个应该可以。 Please mark my answer as solved if it helps.如果有帮助,请将我的答案标记为已解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM