473,406 Members | 2,352 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,406 software developers and data experts.

Toolstrip menu items in C# 2.0

My application has a main tool strip menu (File, Options, help,...).
There are also a number of context menu's that popup.

Some main menu items should also be available in some context menu's.

Is there a way of defining these shared menu items once, and merge
them in the main menu and context menu. I don't want to create the
same menu's and handling the same event handlers.

What approach is there for sharing menu items, so that there can be a
central point to manage menu item state and handling menu item events
without redundant code?

Thanks!
--
Ludwig Stuyck
http://www.coders-lab.be
Jun 7 '06 #1
2 9758
Ludwig wrote:
My application has a main tool strip menu (File, Options, help,...).
There are also a number of context menu's that popup.

Some main menu items should also be available in some context menu's.

Is there a way of defining these shared menu items once, and merge
them in the main menu and context menu. I don't want to create the
same menu's and handling the same event handlers.

What approach is there for sharing menu items, so that there can be a
central point to manage menu item state and handling menu item events
without redundant code?

Thanks!


Ludwig,

I'm not extremely experienced with WinForms, but I can't really think of
any easy way to accomplish what you want to do.

The best approach I can think of would to be write a method which takes
in a String name, a ContextMenu, a ToolStripMenuItem, and an
EventHandler, and then use that to create the menu items and prevent
repeating yourself in code.

Example:

public void CreateMenuItems(string name, ContextMenu contextMenu,
ToolStripMenuItem toolStripMenuItem, EventHandler handler)
{
contextMenu.MenuItems.Add(new MenuItem(name, handler));
toolStripMenuItem.DropDownItems.Add(new ToolStripMenuItem(name,
null, handler));
}

Now you have the event handler on both menu items, with the menu item
showing up in both places, but only created one place in code.

Hopefully this will help, maybe somebody will know of a better way.

Dan Manges
Jun 7 '06 #2
To me I will be lazy to just creat a method the but of the toolstrip menu
and context menu call that method.

chanmm

"Ludwig" <no**@none.com> wrote in message
news:1e********************************@4ax.com...
My application has a main tool strip menu (File, Options, help,...).
There are also a number of context menu's that popup.

Some main menu items should also be available in some context menu's.

Is there a way of defining these shared menu items once, and merge
them in the main menu and context menu. I don't want to create the
same menu's and handling the same event handlers.

What approach is there for sharing menu items, so that there can be a
central point to manage menu item state and handling menu item events
without redundant code?

Thanks!
--
Ludwig Stuyck
http://www.coders-lab.be

Jun 7 '06 #3

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

Similar topics

1
by: GatorBait | last post by:
Hi all, I'm using the new ToolStrip control in a project and I'm running into a problem that I'm hoping someone can help me with. I am building the toolstrip in code by adding buttons,...
0
by: gene kelley | last post by:
I'm migrating/rewriting one of my VB6 apps to VB2005. In the process, I'm trying to avoid using third party activex controls used in the VB6 project. One of the third party controls in the VB6...
4
by: poppy | last post by:
I am having trouble creating a menu item. The Code I have: private void NewLoad(object sender, System.EventArgs e) { //error here ToolStripItem mn = (ToolStripItem)sender; } The error I...
4
by: Adam Honek | last post by:
I have a ToolStrip. The ToolStrip has a ToolStripDropDownButton with 3 ToolStripMenuItems My question is how do I catch the click event ot these 3 ToolStripMenuItems? I tried the below but...
4
by: gene kelley | last post by:
The default ToolStrip apparently renders an MS Office Style ToolStrip when the RenderMode is other than "System". When using a BackgroundImage in the ToolStrip, this Office Style border has rounded...
0
by: Jon Davis | last post by:
I'm taking the items from a menustrip of a control and moving them to the parent form's menustrip: private void TakeMenus(AdminControl ac) { foreach (Control c in ac.Controls) { if (c is...
1
by: Franky | last post by:
I saw the following on the Internet and wonder if you have any inside info about future improvements to the ToolStrip family that can be shared ? Is it possible to have the same items in two...
2
by: Doc John | last post by:
After I've added the menustrip and the toolstrip to my MDI windows Form (and I've added their respective items), I notice that the items disappear. They're still in the code, but the association...
3
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
Ok, I have a menuStrip and a toolStrip. the menuStrip is laid out like this: Actions Connect Disconnect - Exit Pretty simple. The toolstrip has 1 item, a toolstripstatus. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.