【问题标题】:Visual Basic: Make 1 button do 2 operationsVisual Basic:使 1 个按钮执行 2 个操作
【发布时间】:2014-03-17 16:39:00
【问题描述】:

所以我需要一个按钮来完成两个操作,但分两个步骤。这是第一个按钮代码:

第一个按钮(button6)

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

    p = Process.GetProcessesByName("SbieSvc")
    If p.Count > 0 Then
        Environment.Exit(0)
    Else

    End If
    Dim antiProcess() As String = {"SbieSvc", "Sandboxiecrypto", "sbiectrl"}
    For intI As Integer = 0 To antiProcess.GetUpperBound(0)
        For Each x As Process In Process.GetProcessesByName(antiProcess(intI))
            x.Kill()
        Next
    Next
    ''Sets the Channel''
    If TextBox6.Text = "" Then
        MsgBox("Please enter a Channelname!", MsgBoxStyle.Information, ("Error"))
        GoTo Bottom
    End If
    Me.Data = Me.TextBox6.Text
    Me.Method_1(String.Format("Channel set ({0})", Data))
    If (Me.thread0 Is Nothing) Then
        Me.thread0 = New Thread(New ThreadStart(AddressOf Method2)) With
        {
            .IsBackground = True
        }
        Me.thread0.Start()
    End If
    ''Part Of Grab Urls Method''
    Button6.Enabled = False
    For i As Integer = 0 To TextBox5.Text Step 1
        Dim t1 As New Thread(New ParameterizedThreadStart(Sub() GetUrls(TextBox6.Text)))
        t1.Start()
    Next
    GC.SuppressFinalize(Me)
End Sub

  Second button (button1)  

    Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
    ''start live viewers''
    Button1.Enabled = False
    For Each itemss In Urls.Items
        Dim t1 As New Threading.Thread(Sub() LivePeepz(itemss))
        t1.Start()
    Next
End Sub

我将如何编写此代码,以便 button6 将完成它的正常命令,然后一旦完成它就会开始 button1 的操作。我想过这样做;

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

    p = Process.GetProcessesByName("SbieSvc")
    If p.Count > 0 Then
        Environment.Exit(0)
    Else

    End If
    Dim antiProcess() As String = {"SbieSvc", "Sandboxiecrypto", "sbiectrl"}
    For intI As Integer = 0 To antiProcess.GetUpperBound(0)
        For Each x As Process In Process.GetProcessesByName(antiProcess(intI))
            x.Kill()
        Next
    Next
    ''Sets the Channel''
    If TextBox6.Text = "" Then
        MsgBox("Please enter a Channelname!", MsgBoxStyle.Information, ("Error"))
        GoTo Bottom
    End If
    Me.Data = Me.TextBox6.Text
    Me.Method_1(String.Format("Channel set ({0})", Data))
    If (Me.thread0 Is Nothing) Then
        Me.thread0 = New Thread(New ThreadStart(AddressOf Method2)) With
        {
            .IsBackground = True
        }
        Me.thread0.Start()
    End If
    ''Part Of Grab Urls Method''
    Button6.Enabled = False
    For i As Integer = 0 To TextBox5.Text Step 1
        Dim t1 As New Thread(New ParameterizedThreadStart(Sub() GetUrls(TextBox6.Text)))
        t1.Start()
    Next
    GC.SuppressFinalize(Me)
    ''start live viewers''
    Button1.Enabled = False
    For Each itemss In Urls.Items
        Dim t1 As New Threading.Thread(Sub() LivePeepz(itemss))
        t1.Start()
End Sub

但这不起作用...有什么想法吗?谢谢。 VB2012

【问题讨论】:

    标签: vb.net


    【解决方案1】:

    将您的代码放在单独的函数中,例如Function1 将包含您打算用于第一次按钮单击的代码。 Function2 将具有用于第二次按钮单击的代码。

    然后你有一个带有 onClick 事件代码的按钮

    Private Sub Button1_Click(byVal sender as Object, byVal e as EventArgs) Handles Button1.Click
    
        Function1()
        Function2()
    
    End Sub
    

    【讨论】:

      【解决方案2】:
      Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
      FirstOperation()
      SecondOperation()
      End Sub
      
      Private Sub FirstOperation()
      'Button 6 Code
      End Sub
      
      Private Sub SecondOperation()
      'Button 1 Code
      End Sub
      

      【讨论】:

        猜你喜欢
        • 2013-10-16
        • 1970-01-01
        • 2014-07-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多