日期:2014-05-18 浏览次数:20890 次
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frmA As New FormA frmA.Show() Dim frmB As New FormB frmB.Show() End Sub End Class Public Class FormA Inherits System.Windows.Forms.Form Public Sub New() Dim btn As New Button btn.Text = "Button(&S)" AddHandler btn.Click, AddressOf ButtonClick Me.Controls.Add(btn) Me.Text = "FormA" End Sub Private Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) MsgBox("FormA") End Sub End Class Public Class FormB Inherits System.Windows.Forms.Form Public Sub New() Dim btn As New Button btn.Text = "Button(&S)" AddHandler btn.Click, AddressOf ButtonClick Me.Controls.Add(btn) Me.Text = "FormB" End Sub Private Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) MsgBox("FormB") End Sub End Class
------解决方案--------------------
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim frmA As New FormA Dim frmB As New FormB Dim panel1 As New Panel panel1.Dock = DockStyle.Fill panel1.Controls.Add(frmA) panel1.Controls.Add(frmB) frmA.Location = New Point(10, 10) frmB.Location = New Point(10, frmA.Location.Y + frmA.Height + 10) Me.Controls.Add(panel1) End Sub End Class Public Class FormA Inherits System.Windows.Forms.UserControl Public Sub New() Me.BorderStyle = Windows.Forms.BorderStyle.FixedSingle Dim btn As New Button btn.Text = "ButtonA(&S)" AddHandler btn.Click, AddressOf ButtonClick Me.Controls.Add(btn) Me.Text = "FormA" End Sub Private Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) MsgBox("FormA") End Sub End Class Public Class FormB Inherits System.Windows.Forms.UserControl Public Sub New() Me.BorderStyle = Windows.Forms.BorderStyle.FixedSingle Dim btn As New Button btn.Text = "ButtonB(&S)" AddHandler btn.Click, AddressOf ButtonClick Me.Controls.Add(btn) Me.Text = "FormB" End Sub Private Sub ButtonClick(ByVal sender As Object, ByVal e As System.EventArgs) MsgBox("FormB") End Sub End Class
------解决方案--------------------
注意这两处:
1、Public Class FormA
Inherits System.Windows.Forms.UserControl
2、Public Class FormB
Inherits System.Windows.Forms.UserControl