MainMenu appears on wrong form

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
 
K

Katie Schaeffer [MSFT]

Hi Richard,

This is a known bug...I believe it was fixed in SP1. To workaround this,
create Form2's menu before you create Form1's menu.

-Katie

This posting is provided "AS IS" with no warranties, and confers no rights.

***.Net Compact Framework Info***
Faq:
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.a
spx
QuickStarts: http://samples.gotdotnet.com/quickstart/CompactFramework/
Samples:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/h
tml/CompactfxTechArt.asp

--------------------
| From: "Richard K" <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| Subject: MainMenu appears on wrong form
| Date: Sat, 13 Dec 2003 08:37:55 -0600
| Organization: Info Avenue Internet Services, LLC
| Lines: 93
| Message-ID: <[email protected]>
| NNTP-Posting-Host: 207.144.199.81
| X-Trace: news3.infoave.net 1071326295 234631 207.144.199.81 (13 Dec 2003
14:38:15 GMT)
| X-Complaints-To: (e-mail address removed)
| NNTP-Posting-Date: Sat, 13 Dec 2003 14:38:15 +0000 (UTC)
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFTNGXA0
5.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-online.de!newsfe
ed.esat.net!nntp.theplanet.net!inewsm1.nntp.theplanet.net!195.40.4.120.MISMA
TCH!easynet-quince!easynet.net!news-out1.nntp.be!propagator2-sterling!news-i
n-sterling.newsfeed.com!news.infoave.net!not-for-mail
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.compactframework:40813
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| 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
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top