473,753 Members | 7,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9784
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 ToolStripMenuIt em, 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,
ToolStripMenuIt em toolStripMenuIt em, EventHandler handler)
{
contextMenu.Men uItems.Add(new MenuItem(name, handler));
toolStripMenuIt em.DropDownItem s.Add(new ToolStripMenuIt em(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.co m> wrote in message
news:1e******** *************** *********@4ax.c om...
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
3064
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, seperators, and dropdown buttons (which have MenuItems added to it). The ToolStrip gets built perfectly, but the problem I am having is accessing the click event of the dropdown button's menuitems. I hope someone can help!!! Thank you so much in...
0
1761
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 app was for menu/toolbars. This control had an option to render the toolbar in an Office 2003 style which is nothing more than a top to bottom gradient. When a new ToolStrip is added to a form, the default appearance of the Toolstrip is that of...
4
11313
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 get is :
4
9178
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 it doesn't catch the events: Private Sub LowPriorityToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
4
11462
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 corners and looks like hell. According to the Help file: To change the Microsoft Office–style borders to straight Override...
0
2273
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 MenuStrip) { MenuStrip ms = (MenuStrip)c;
1
1640
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 different MenuStrip controls, for example the main menu and a context menu? With the entire ToolStrip family of controls we do not have an integrated commanding architecture nor do we support cloning of items to
2
5043
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 between the bar and the items (i.e. toolStrip.Items.AddRange) disappears. How come? This is happening frequently. After I fix it, it erases it again. I'm currently adding these menu controls to an mdi application built in VS2002 and successfully...
3
7835
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 decided I wanted to add a little icon next to the status text, so I opened up the image property in Design mode and imported 2 images. Both were PNG images and were 256x256 resolution. I decided that I wanted to use smaller versions since it was, after...
0
8896
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9653
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9333
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8328
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4771
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3395
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2872
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2284
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.