We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Enabling/disabling items in Edit Menu - XPMenus

Thread ID:





36851 Nov 10,2005 11:05 PM UTC Nov 12,2005 05:36 PM UTC WinForms 3
Tags: Tools
Asked On November 10, 2005 11:05 PM UTC

I made a nice pretty Edit menu for my application, and now I guess I face a common dilemma - how to enable/disable the menu items depending on what kind of control has the focus. Here''s an excerpt of my code: // Edit ParentBarItem biEdit = new ParentBarItem("Edit"); biEdit.Popup += new System.EventHandler(Edit_Popup); // Undo bi = new BarItem("Undo"); bi.ImageIndex = 6; bi.Shortcut = Shortcut.CtrlZ; bi.ShortcutText = "Ctrl+Z"; bi.Click += new System.EventHandler(Undo_Click); biEdit.Items.Add(bi); // Redo bi = new BarItem("Redo"); bi.ImageIndex = 7; bi.Shortcut = Shortcut.CtrlY; bi.ShortcutText = "Ctrl+Y"; bi.Click += new System.EventHandler(Redo_Click); biEdit.Items.Add(bi); // Cut bi = new BarItem("Cut"); bi.ImageIndex = 3; bi.Shortcut = Shortcut.CtrlX; bi.ShortcutText = "Ctrl+X"; bi.Click += new System.EventHandler(Cut_Click); biEdit.Items.Add(bi); biEdit.BeginGroupAt(bi); Here''s an article on CodeProject where a guy came up with an entire system for doing this, though of course he implemented it for standard .NET menus: http://www.codeproject.com/cs/menu/TcMagicalEditMenu.asp One nice thing about his solution is he defines an interface and you can implement this interface in your own controls. He takes care of textboxes and comboboxes. What do you guys recommend? Jim

Replied On November 11, 2005 07:24 PM UTC

Hmmmm...nobody has pondered this problem before?

Administrator [Syncfusion]
Replied On November 12, 2005 12:57 PM UTC

Hi Jim, Using the Control''s type and state to enable/disable and hide/show the various edit menu items looks fine. The ParentBarItem''s BeforePopup event can be used to determine the focused control,call a method to get state flags, then setup the edit menu based on the flags. Regards, Ebenezer.P

Replied On November 12, 2005 05:36 PM UTC

OK, I was hoping someone might already have some code for this. I realize it''s not really a responsiblity of Syncfusion to supply this kind of code, I was just hoping that either you guys or one of the forum members might have something already, because it seems like it would be a common problem that everybody encounters sooner or later. I can try to either adapt the CodeProject article or roll my own solution, if nobody else has anything. Maybe I can send my solution to you for posting in the KB. Question: do I need to implement an event handler for Cut|Copy|Paste and somehow pass the message on to the control with the focus? Or if I do not implement an event handler, does a message somehow get magically passed through to the control with focus? Jim


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon