busyme

Hi,

I derived a form that has a menu strip. I set the Modifiers option to Protected and also tried Public on the base form, but the menu strip remains locked after you inherited the form. How do I unlock the menu strip on the derived form

Busyme



Re: Windows Forms General MenuStrip remains locked on the inherited form

busyme

Anyone can help me on this Or is this a bug





Re: Windows Forms General MenuStrip remains locked on the inherited form

ThE_lOtUs

If I'm correct. VS can only modify the form that is currently open. So if your form inherit from an other form it cannot change the parent one when you are in the child one. The only way to change it is through the code.






Re: Windows Forms General MenuStrip remains locked on the inherited form

Andrej Tozon

Hi,

This behaviour is by design and is sometimes referred to as Visual Inheritance lockdown "feature"... You'll have to manipulate MenuStrip's properties manually in the code.

Andrej






Re: Windows Forms General MenuStrip remains locked on the inherited form

busyme

How Do you a have sample code to be able to add more menu items on the menu strip that is locked

Thanks





Re: Windows Forms General MenuStrip remains locked on the inherited form

Andrej Tozon

Put the following code in your inherited form's constructor (after InitializeComponent line):

Code Snippet

ToolStripMenuItem item = new ToolStripMenuItem("&Menu 1");

item.DropDownItems.Add("&Item 1");

item.DropDownItems.Add("&Item 2");

baseMenuStrip.Items.Add(item);

[baseMenuStrip is original MenuStrip control on the base form]

Andrej






Re: Windows Forms General MenuStrip remains locked on the inherited form

busyme

Andrej,

It appears that the menu item got added on the menu strip during debug mode,

but when I actually run my application, the item does not show up.





Re: Windows Forms General MenuStrip remains locked on the inherited form

Andrej Tozon

What do you mean by actually run the application Running an .exe file should have the same effect as running in VS IDE, unless some conditional statements are involved...

Andrej






Re: Windows Forms General MenuStrip remains locked on the inherited form

busyme

After I added the code under the Initial Component, the menu item appears on the derived menu strip, however, when I click on Start Debugging, the menu item does not show up.





Re: Windows Forms General MenuStrip remains locked on the inherited form

wjousts

Don't edit the Visual Studio generated code, it probably erased any changes you made which it will sometimes do. Add extra menu items in the form constructor after the InitializeComponents call.

Personally, I like to add a context menu to my form and use that for visual design. Then in the constructor I just make it merge the items from my context menu into the main menu.





Re: Windows Forms General MenuStrip remains locked on the inherited form

Andrej Tozon

...and make sure you're instantiating and showing the derived form, not the base one... I've seen this one a couple of times...

Andrej






Re: Windows Forms General MenuStrip remains locked on the inherited form

busyme

Why do I have to add the item on the base menu strip and not the derived form as is indicated on your code





Re: Windows Forms General MenuStrip remains locked on the inherited form

Andrej Tozon

You should put the above code in your derived form's constructor, adding additional items to the menu strip, declared on your base form [where you set its Modifier property to Protected].

Meaning - in your derived form, you're accessing and modifying the menu strip control, inherited from the base form, where it's originaly declared.

Andrej






Re: Windows Forms General MenuStrip remains locked on the inherited form

busyme

I see. Now I know what my problem is. I am accessing this form from another inherited form called LoginForm. LoginForm calls this form, but since they both are located in the same class Library I am referencing, LoginForm invokes the original form. How do I call the derived form instead of the original form if anyone can use a different for it The login form has the code to open the original form. Can I add the derived form name in the app.config and refer to that in the base LoginForm But how do I create an instance of that form from the base LoginForm

Thanks





Re: Windows Forms General MenuStrip remains locked on the inherited form

busyme

I guess, what I like to do is extract the name of the Form from the app.config file and convert it to a Form Object and instantiate it within my code. Do you have a code that does similar to this that you can give me

Thanks