Menu Bug in Compact Framework...

R

Russ Ryba

I believe I've found a bug in the compact framework. I don't see any
reference to it, but here's what I've found. I'm testing on a Dell Axim
X5, PocketPC 2002, A03 ROM.

If you create a new instance of a form inside a different forms Load
Event, the first form gets the seconds forms menu. I was creating the
child forms at startup so all the waiting happened at once and the rest
of the application loaded quicker. Everything worked great until I
tried adding a menu for the SIP control.

Starting the application will show the wrong menu in both the handheld
and the emulator. I've attached a zip of the files used to create the
project.

Here is the Minimum Code I've found to reproduce this bug.
----------------------------------------------------------------------------------
== Form1.vb ==
----------------------------------------------------------------------------------
Public Class Form1
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem

#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MainMenu1.MenuItems.Add(Me.MenuItem1)
Me.MenuItem1.Text = "FORM1"
Me.Menu = Me.MainMenu1
Me.Text = "Form1"
End Sub
#End Region

Dim A As Form2
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs)
A.Show()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
A = New Form2
End Sub
End Class

----------------------------------------------------------------------------------
== Form2.vb ==
----------------------------------------------------------------------------------
Public Class Form2
Inherits System.Windows.Forms.Form
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()
InitializeComponent()
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub

<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MainMenu1.MenuItems.Add(Me.MenuItem1)
Me.MenuItem1.Text = "FORM2"
Me.Menu = Me.MainMenu1
Me.Text = "Form2"
End Sub

#End Region

End Class
 
D

Daniel Moth

Your sample was missing the Handles clause on the menu click handler (hence
it wouldn't run and it wouldn't show the second form). Anyway, after adding
that, I run it and it worked fine. When the second form appeared it had its
own menu FORM 2. This is on an iPAQ (based on CE 4.2) running SP3 Beta.

By the way, any initialisation you want to do that does not depend on UI
layout, it is best to do in the ctor of the form, not the Load event.

Run it in the emulator (PPC2002 running RTM) and there is some weirdness.
Following my advice of creating the second form in the ctor of the first,
fixes the problem there too. Let me know if it doesn't work for you.

Cheers
Daniel
 
R

Russ Ryba

Daniel said:
Your sample was missing the Handles clause on the menu click handler
(hence it wouldn't run and it wouldn't show the second form). Anyway,
after adding that, I run it and it worked fine. When the second form
appeared it had its own menu FORM 2. This is on an iPAQ (based on CE
4.2) running SP3 Beta.
I removed that. Even though form2 was never shown, Form1 had the menu
defined in Form2. That was the problem I was had.
By the way, any initialisation you want to do that does not depend on UI
layout, it is best to do in the ctor of the form, not the Load event.

Run it in the emulator (PPC2002 running RTM) and there is some
weirdness. Following my advice of creating the second form in the ctor
of the first, fixes the problem there too. Let me know if it doesn't
work for you.

Cheers
Daniel
--

Thanks for the advice. That did the trick. :blush:)
 

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

Similar Threads


Top