Visual Basic:使1个按钮执行2个操作

时间:2014-03-17 16:39:00

标签: vb.net

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

第一个按钮(按钮6)

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完成它的正常命令,然后一旦完成它就开始按钮1的操作。我想过这样做;

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

2 个答案:

答案 0 :(得分:0)

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

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

的按钮
Private Sub Button1_Click(byVal sender as Object, byVal e as EventArgs) Handles Button1.Click

    Function1()
    Function2()

End Sub

答案 1 :(得分:0)

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