| EventではなくAction型で定義すればNothingの判断が出来るので可能かと思います。
'--- Button1, 2を配置
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using fm2 As New Form2()
fm2.ShowDialog(Me)
End Using
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Using fm2 As New Form2()
fm2.TestEvent = Sub()
fm2.Label1.Text = "Form1側で設定処理を実行"
End Sub
fm2.ShowDialog(Me)
End Using
End Sub
End Class
'--- Button1とLabel1を配置
Public Class Form2
Public Property TestEvent As Action = Nothing
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TestEvent Is Nothing Then
Label1.Text = "Form2側で設定処理を実行"
Else
TestEvent.Invoke()
End If
End Sub
End Class |