' Form2.vb
Public Event DataSent(value As String)
Private Sub Form2_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
RaiseEvent DataSent(txtInput.Text)
End Sub
' Form1.vb
Dim f2 As New Form2()
AddHandler f2.DataSent, AddressOf Me.OnDataReceived
f2.Show()
Private Sub OnDataReceived(value As String)
Me.Text = "收到:" & value
End Sub
Dim f2 As New Form2()
If f2.ShowDialog() = DialogResult.OK Then
Me.Text = f2.ReturnValue ' Form2 公共屬性
End If
適用於「模態等待結果」場景。