在Form1裡宣告變數a、b、c 新增Button1、Button2、TextBox1 並且再Button1的Click事件中寫出計算方法 Button2的Click事件是Form2的Show Public Class Form1 Friend a, b, c As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = a + b + c End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Form2.Show() End Sub End Class 新增windows窗體Form2,然後在Form2裡新增TextBox1、TextBox2、TextBox3 在Form2的FormClosing事件中將TextBox裡的值傳遞給Form1的變數a、b、c Public Class Form2 Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Form1.a = CInt(Me.TextBox1.Text) Form1.b = CInt(Me.TextBox2.Text) Form1.c = CInt(Me.TextBox3.Text) End Sub End Class
在Form1裡宣告變數a、b、c 新增Button1、Button2、TextBox1 並且再Button1的Click事件中寫出計算方法 Button2的Click事件是Form2的Show Public Class Form1 Friend a, b, c As Integer Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = a + b + c End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Form2.Show() End Sub End Class 新增windows窗體Form2,然後在Form2裡新增TextBox1、TextBox2、TextBox3 在Form2的FormClosing事件中將TextBox裡的值傳遞給Form1的變數a、b、c Public Class Form2 Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing Form1.a = CInt(Me.TextBox1.Text) Form1.b = CInt(Me.TextBox2.Text) Form1.c = CInt(Me.TextBox3.Text) End Sub End Class