2011-06-15 57 views

回答

0

创建的第一个用户控制共享的事件(的UserControl1):

Friend Shared Event GetTextBoxText(ByVal myString As String) 

可以再提高一个按钮这一事件上(的UserControl1)

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 

    'raise the event with the text from the text box 
    RaiseEvent GetTextBoxText(TextBox1.Text) 

End Sub 
在你的第二个用户控件

( UserControl2)在您的构造函数中为事件添加处理函数:

Public Sub New() 

    ' This call is required by the designer. 
    InitializeComponent() 

    ' Add any initialization after the InitializeComponent() call. 

    'this will let us handle the event from (UserControl1) 
    AddHandler UserControl1.GetTextBoxText, AddressOf SetLabelText 

End Sub 

Private Sub SetLabelText(ByVal myString As String) 
    Label1.Text = myString 
End Sub 

现在每当yo ü点击(的UserControl1)的文本按钮将显示在标签上UserControl2

,你还可以添加任何控件的事件处理程序,并GetTextBoxText事件

+0

回应是否有更简单的方法来做到这一点?我有很多值从许多用户控件传递到一个主用户控件。用你的方法,我将不得不为每个想要传递的值创建一个处理函数和一个子函数。 – NuWin 2016-05-16 02:15:56

相关问题