The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
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
ADAdministrator Syncfusion Team 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
JIJim 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