尝试在您Button1_Click()
的处理程序开始时调用您的处理Button5_Click
程序:
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Button1_Click() 'Call the handler at the start of your subroutine
If Not IsNumeric(TextBox6.Text) Or Not IsNumeric(TextBox7.Text) Or Not IsNumeric(TextBox8.Text) Or Not IsNumeric(TextBox9.Text) Then
MessageBox.Show("Invalid Input", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf 99 >= TextBox6.Text Or 99 >= TextBox7.Text Or 99 >= TextBox8.Text Or 99 >= TextBox9.Text Then
MessageBox.Show("Invalid Amount", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Form5.Show()
Me.Hide()
Form5.Label3.Text = TextBox1.Text
Form5.Label5.Text = TextBox2.Text
Form5.Label7.Text = TextBox3.Text
Form5.Label9.Text = ComboBox1.Text
Form5.Label11.Text = TextBox4.Text
Form5.Label13.Text = ComboBox2.Text
Form5.Label15.Text = Label27.Text
Form5.Label22.Text = Label14.Text
Form5.Label17.Text = Label22.Text
Form5.Label19.Text = Label25.Text
End If
End Sub
假设Button1_Click()
处理“计算”部分,这应该适合你。
一种更简单的编写方法是编写上下文命名的子例程,然后从单击处理程序中调用这些例程。
例子:
Private Sub Compute()
'Do computations
'Use a function instead of a sub if you need to return a value.
End Sub
Private Sub Summarize()
If Not IsNumeric(TextBox6.Text) Or Not IsNumeric(TextBox7.Text) Or Not IsNumeric(TextBox8.Text) Or Not IsNumeric(TextBox9.Text) Then
MessageBox.Show("Invalid Input", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
ElseIf 99 >= TextBox6.Text Or 99 >= TextBox7.Text Or 99 >= TextBox8.Text Or 99 >= TextBox9.Text Then
MessageBox.Show("Invalid Amount", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Form5.Show()
Me.Hide()
Form5.Label3.Text = TextBox1.Text
Form5.Label5.Text = TextBox2.Text
Form5.Label7.Text = TextBox3.Text
Form5.Label9.Text = ComboBox1.Text
Form5.Label11.Text = TextBox4.Text
Form5.Label13.Text = ComboBox2.Text
Form5.Label15.Text = Label27.Text
Form5.Label22.Text = Label14.Text
Form5.Label17.Text = Label22.Text
Form5.Label19.Text = Label25.Text
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Compute() 'Call compute subroutine
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Compute() 'Call compute subroutine
Summarize() 'Call summarize subroutine
End Sub