main menu appears prematurely

  • Thread starter Thread starter marcmc
  • Start date Start date
Here is a minimal example. The Form2 MenuItem appears on Form1 immediately
when "Frm2 = New Form2" is executed. However when the button on Form2
redisplays Form1, the menu item is now gone. It appears that executing "New
FormX" where FormX contains a MainMenu makes the new form's menu visible on
the currently visible form, instead of waiting until the new form is made
visible.

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
NOW
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

<System.Diagnostics.DebuggerStepThrough()> 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
 
Hi Richard,

There was a known bug simular to what you're describing. Could you try
running your code on a device with SP2 installed?

Thanks,
-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: Re: main menu appears prematurely
| Date: Fri, 12 Dec 2003 10:33:17 -0600
| Organization: Info Avenue Internet Services, LLC
| Lines: 130
| Message-ID: <[email protected]>
| References: <[email protected]>
<[email protected]>
| NNTP-Posting-Host: 207.144.199.140
| X-Trace: news3.infoave.net 1071246822 190095 207.144.199.140 (12 Dec 2003
16:33:42 GMT)
| X-Complaints-To: (e-mail address removed)
| NNTP-Posting-Date: Fri, 12 Dec 2003 16:33:42 +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!cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.su
l.t-online.de!t-online.de!nntp-relay.ihug.net!ihug.co.nz!logbridge.uoregon.e
du!arclight.uoregon.edu!news.infoave.net!not-for-mail
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.compactframework:40759
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Here is a minimal example. The Form2 MenuItem appears on Form1
immediately
| when "Frm2 = New Form2" is executed. However when the button on Form2
| redisplays Form1, the menu item is now gone. It appears that executing
"New
| FormX" where FormX contains a MainMenu makes the new form's menu visible
on
| the currently visible form, instead of waiting until the new form is made
| visible.
|
| 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
| NOW
| 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
|
| <System.Diagnostics.DebuggerStepThrough()> 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
|
| | > still cannot recreate this!
| >
| > >-----Original Message-----
| > >Someone else asked this a while back but didn't get an
| > answer.
| > >
| > >If FormA (startup) has an "empty" main menu, and it
| > creates (but does not
| > >immediately show) FormB which has a "real" populated
| > menu, then...
| > >
| > >the FormB menu appears at the bottom of FormA as soon as
| > FormB has been
| > >created. If haven't tried any experiments, but I
| > suspect that anytime a
| > >form containing a visible menu is created the new form's
| > menu will appear on
| > >the current form.
| > >
| > >Hiding the new form (which shouldn't be necessary
| > anyway) does not get rid
| > >of its menu, and there is no MainMenu.Hide method.
| > >
| > >Is there any way around this?
| > >
| > >thanks
| > >
| > >Dick
| > >
| > >
| > >.
| > >
|
|
|
 
Back
Top