查看UserControls(Composite Controls)。它们将允许您创建带有事件和属性的自定义布局并将其添加到您的面板中。我用它来换入/换出我的应用程序的编辑页面。
这是一个非常简单的例子:(1个表单,2个面板,2个用户控件)
表格1
Public Class Form1
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub UserControl11_SendText(value As String) Handles UserControl11.SendText
UserControl12.SetText(value)
End Sub
Private Sub UserControl12_SendText(value As String) Handles UserControl12.SendText
UserControl11.SetText(value)
End Sub
End Class
用户控制
Public Class UserControl1
Public Event SendText(ByVal Text As String)
Public Sub SetText(value As String)
Label1.Text = value
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
RaiseEvent SendText(TextBox1.Text)
End Sub
End Class