473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Working with the MenuStrip

I am converting from MainMenu to MenuStrip And I want to list the hierarchy
of a clicked menu item. With the MainMenu, it was easy to do using the
parent property of the MenuItem. With the ToolStripMenuItem, it no longer
works.

To better understand my need, please create a VS form and add a MenuStrip,
button and two labels to it with the default names then add the code shown
below to the form. What I need is code in the menuClick method that adds the
names of the parent and grandparent of the clicked menu item (when clicking
the last item in the menu hierarchy). This should be simple to do but my
searches on the Web and experiments with the GetParent() method and parent
property were fruitless. What am I missing?

{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private System.Windows.Forms.ToolStripMenuItem tsItem1;
private System.Windows.Forms.ToolStripMenuItem tsItem2;
private System.Windows.Forms.ToolStripMenuItem tsItem3;
private System.Windows.Forms.ToolStripMenuItem tsItem4;

private void menuClick(object sender, System.EventArgs e)
{
ToolStripMenuItem oStrip = ((ToolStripMenuItem)(sender));
this.label1.Text = "My parent is: "; //I want it to say
“My parent is Down Two Levels!!”

this.label2.Text = "My grandparent is: "; //I want it to
say “My grandparent is Down One Level!!”
}

private void button1_Click(object sender, EventArgs e)
{
this.tsItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.tsItem2 = new System.Windows.Forms.ToolStripMenuItem();
this.tsItem3 = new System.Windows.Forms.ToolStripMenuItem();
this.tsItem4 = new System.Windows.Forms.ToolStripMenuItem();
this.tsItem1.Text = "Menu Strip Level";
this.tsItem2.Text = "Down One Level";
this.tsItem3.Text = "Down Two Levels";
this.tsItem4.Text = "Down Three Levels";
tsItem4.Click += new System.EventHandler(menuClick);
this.menuStrip1.Items.Add(tsItem1);
this.tsItem1.DropDownItems.Add(tsItem2);
this.tsItem2.DropDownItems.Add(tsItem3);
this.tsItem3.DropDownItems.Add(tsItem4);
}
}
Sep 21 '06 #1
1 1967
After endless Internet search, I found the answer. Use the

.OwnerItem

property.
Sep 21 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Alvo von Cossel I | last post by:
hi, i have a modern looking application without the cotrolbox-bar because i've created my own. i have a restore down button with an image that has a grey background. if the user has a different...
2
by: Neo | last post by:
Sorry for reposting, subject line was incorrect... These are not working in Visual Studio .NET 2005 beta 1 (no such methods) mainMenu1.MergeMenu(contextMenu1); and
0
by: rellik | last post by:
Hi All, I've run into a problem with the MenuStrip control and any help would be greatly appreciated! The problem I've got is that when use a control derived from the MenuStrip class all MDI...
0
by: Chris Peeters | last post by:
Hi, I have an MDI-application running with 1 MDI chilld showing in 'Normal'-WindowState, so NOT maximized. What I see is the MDI-main window showing its title bar, below that the menustrip with...
1
by: Schwammkopf | last post by:
Hi ! I'm using Visual Studio 2005 Professional Edition and C#. I have a simple question: I want to add to my form, which is a scrollable control, a menustrip and statusstrip. The problem is...
0
by: active | last post by:
For the last 3 or 4 days I've been, on an off, searching the Internet and theVS2005 Doc for an example of how to add a contextmenustrip to a menustrip. I can move all the items from a...
3
by: Gav | last post by:
I am using a MenuStrip on a form and adding a Panel to the same form in the program. When the Panel is added the top of the Panel is behind the MenuStrip, so the top of the Panel is hidden. How do...
0
by: kyungdongkim | last post by:
Hi, I have a dynamically generated MenuStrip following this example: http://www.codeproject.com/useritems/Dynamic_MenuStrip.asp Basically the menu strip allows users to save and load reports. ...
3
by: ssknov | last post by:
hi i am creating a login page.Inthe form load itself i need to hide the MenuStrip in MDI Parent to HIDE, When the users gives the correct passwd and pushes the Loginbutton , My MDIParent1 forms...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.