R
Richard K
Can anyone tell me how to prevent this? If Form1 (which has a blank
MainMenu) dynamically creates Form2 (which has a populated MainMenu), the
Form2 menu appears at the bottom of Form1 as soon as the VB line "Frm2 = New
Form2" is executed, even though Form2 is not visible yet. Here is a short
example:
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.Button1 = New System.Windows.Forms.Button
Me.Button1.Location = New System.Drawing.Point(74, 125)
Me.Button1.Size = New System.Drawing.Size(92, 20)
Me.Button1.Text = "Show Form2"
Me.Controls.Add(Me.Button1)
Me.Menu = Me.MainMenu1
Me.MinimizeBox = False
Me.Text = "Form1"
End Sub
Private Frm2 As Form2
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox("Creating Form2")
Frm2 = New Form2 ' <-- FORM2 MENU ITEM APPEARS ON FORM1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Frm2.Frm1 = Me
Frm2.Show()
Me.Hide()
End Sub
End Class
Public Class Form2
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.Button1 = New System.Windows.Forms.Button
Me.MainMenu1.MenuItems.Add(Me.MenuItem1)
Me.MenuItem1.Text = "Menu Item"
Me.Button1.Location = New System.Drawing.Point(74, 136)
Me.Button1.Size = New System.Drawing.Size(92, 20)
Me.Button1.Text = "Show Form1"
Me.Controls.Add(Me.Button1)
Me.Menu = Me.MainMenu1
Me.Text = "Form2"
End Sub
Public Frm1 As Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Frm1.Show()
Me.Hide()
End Sub
End Class
MainMenu) dynamically creates Form2 (which has a populated MainMenu), the
Form2 menu appears at the bottom of Form1 as soon as the VB line "Frm2 = New
Form2" is executed, even though Form2 is not visible yet. Here is a short
example:
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.Button1 = New System.Windows.Forms.Button
Me.Button1.Location = New System.Drawing.Point(74, 125)
Me.Button1.Size = New System.Drawing.Size(92, 20)
Me.Button1.Text = "Show Form2"
Me.Controls.Add(Me.Button1)
Me.Menu = Me.MainMenu1
Me.MinimizeBox = False
Me.Text = "Form1"
End Sub
Private Frm2 As Form2
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox("Creating Form2")
Frm2 = New Form2 ' <-- FORM2 MENU ITEM APPEARS ON FORM1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Frm2.Frm1 = Me
Frm2.Show()
Me.Hide()
End Sub
End Class
Public Class Form2
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.Button1 = New System.Windows.Forms.Button
Me.MainMenu1.MenuItems.Add(Me.MenuItem1)
Me.MenuItem1.Text = "Menu Item"
Me.Button1.Location = New System.Drawing.Point(74, 136)
Me.Button1.Size = New System.Drawing.Size(92, 20)
Me.Button1.Text = "Show Form1"
Me.Controls.Add(Me.Button1)
Me.Menu = Me.MainMenu1
Me.Text = "Form2"
End Sub
Public Frm1 As Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Frm1.Show()
Me.Hide()
End Sub
End Class