Form1側
Dim AA As New UCNT1.UserControl1(Me)
としてAAに自分のインスタンスを送ります。
UserControl1側
Private F1 As Form1
Private Sub New(ByVal _F1 As Form1)
' この呼び出しは、Windows フォーム デザイナで必要です。
InitializeComponent()
' InitializeComponent() 呼び出しの後で初期化を追加します。
F1 = _F1
End Sub
Public Class Form1
Dim AA As New C12.UserControl1(Me)
Public ST As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim BB As String
BB = AA.ABC
TextBox1.Text = BB
End Sub
End Class
Public Class UserControl1
Private _test As String
Private FF1 As Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
_test = "OK"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
_test = "NG"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = _test
End Sub
Public Sub New(ByVal _F1 As Form)
' この呼び出しは、Windows フォーム デザイナで必要です。
InitializeComponent()
' InitializeComponent() 呼び出しの後で初期化を追加します。
FF1 = _F1
End Sub
Private Sub UserControl1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
MyBase.Dispose()
End Sub
Public Function ABC() As String
FF1()
ABC = _test
Return ABC
End Function
End Class