**********
Main
**********
Public Class Form1
Dim AA As New UCNT1.UserControl1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = AA.BTEST
End Sub
End Class
**********
User2 Prop
**********
Public Class Class1
Private _test As String
Public Property Test() As String
Get
Return _test
End Get
Set(ByVal value As String)
_test = value
End Set
End Property
End Class
Public Class UserControl2
Private ATEST As New Class1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ATEST.Test = "OK"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ATEST.Test = "NG"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = ATEST.Test
End Sub
Public Function BTEST() As String
Return ATEST.Test
End Function
End Class
**********
User2 Grob
**********
Public Class UserControl1
Private _test As String
Private Sub New()
' この呼び出しは、Windows フォーム デザイナで必要です。
InitializeComponent()
' InitializeComponent() 呼び出しの後で初期化を追加します。
End Sub
Private Sub UserControl1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
MyBase.Dispose()
End Sub
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
Private Function BTEST() As String
Return _test
End Function
End Class
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