Inherited Forms and menus

  • Thread starter Thread starter Arthur Dent
  • Start date Start date
A

Arthur Dent

Hello all,

I have a small application which has a base form, and forms inherited from
it.
The base form contains a barcode scanner, and a protected event it raise
when the scanner reads data, and the inherited forms can get the scanner and
catch the event with no problems at all.

My problem comes in, with a mainMenu which i have on the base form, which i
expected to see show up on the inherited form, however, it doesnt. This was
kind of the whole reason why i wanted to use a base form, was so i wouldnt
have to duplicate the same menu on a bunch of forms, with duplicate code.
Why does the menu not show up, is there a reason? Anyone know how to fix
this?

Thanks in advance,
- Arthur Dent.
 
VS2005, CF2.

The inherited menu does show up in the component tray at the bottom of the
designer in inherited forms, but it just doesnt render itself on to the
form.
 
Okay, i figured this out....

I dont know *exactly* what was wrong (as far as the code-behinds) but the
problem was something with how the definitions were made.

Originally, id made my first form, then made the master, then tried to
manually code the first form to inherit from the master. Obviously i missed
something.
I added a new form, and chose "inherited form" from the item type list, and
chose the master form when prompted, and now everything is hooked up
beautifully.

Thanks Alex for your help, though.

Cheerz All,
- Arthur Dent.
 
I did precisely the same thing that you did:

1) I had a form -- let's call it "Form1" -- with a MainMenu on it.
2) I then created a base form -- let's call it "BaseForm1" -- also with a MainMenu on it.
3) I then changed Form1 so that it inherited from BaseForm1 instead of System.Windows.Forms.Form, by changing its header line "public partial class Form1 : Form" to "public partial class Form1 : BaseForm1".

I then realized that Form1's MainMenu would no longer be necessary, since BaseForm1's MainMenu should show, so I deleted Form1's MainMenu.

I then opened the form designer for Form1, expecting BaseForm1's MainMenu to show... but it didn't.

So I removed the line "this.Menu = null;" from Form1's InitializeComponent() method, and viola! BaseForm1's MainMenu now shows on Form1.
 
Back
Top