Windows Develop Bookmark and Share   
 index > Windows Forms General > Implementing Cut, Copy, Paste, in a Menu
 

Implementing Cut, Copy, Paste, in a Menu

Here's my situation.  I have a Form with a couple of TextBoxes and a MenuStrip that contains an "Edit" menu with cut, copy, paste, etc.  If I simply have the "Edit" menu items using NO shortcut keys (i.e. Ctrl+X, Ctrl+X, etc) the that functionality works fine in the TextBoxes, for example I can select some text in a TextBox and and use Ctrl+X to cut it.  BUT, if I add shortcut keys to my menu items that functionality goes away, obviously because it hasn't been implemented in my menu items.

My questions is, is there a simple way to have the menu items hook up with/or disregard the textboxes so they still work with their built in functionality?  It seems to me there has to be an easier way to use shortcut keys for my menu items then having to reinvent the wheel for the TextBox controls.

Any help or information on this would be kindly appreciated.

monrobot13  Tuesday, December 13, 2005 6:03 AM
The Textbox, MaskedTextBox and RichTextBox all derive from a common type called TextBoxBase. This type has a number of methods that can be called from the Edit menu of an application:

TextBoxBase.Undo()
TextBoxBase.Cut()
TextBoxBase.Copy()
TextBoxBase.Paste()
TextBoxBase.Clear();
TextBoxBase.SelectAll()

You could simply call these in the appropriate click event handlers of your menu items.
David M. Kean  Tuesday, December 13, 2005 8:44 AM
Moving to the Windows Forms General newsgroup, which is more appropriate for the question.

Jon

Jon Skeet  Tuesday, December 13, 2005 7:33 AM
The Textbox, MaskedTextBox and RichTextBox all derive from a common type called TextBoxBase. This type has a number of methods that can be called from the Edit menu of an application:

TextBoxBase.Undo()
TextBoxBase.Cut()
TextBoxBase.Copy()
TextBoxBase.Paste()
TextBoxBase.Clear();
TextBoxBase.SelectAll()

You could simply call these in the appropriate click event handlers of your menu items.
David M. Kean  Tuesday, December 13, 2005 8:44 AM

You can use google to search for other answers

Custom Search

More Threads

• Cannot access TreeNode.Value property
• Set accessor is not called for Byte[]
• Listbox with icons
• Alert Box
• How can I manually close a BalloonTip?
• Is it possible to get a controls original location on a DragDrop event?
• How to choose the execution thread for a delegate?
• How to impersonate another user to execute a setup.exe file from a winform application?
• Active Hosts on Network
• Highlight border of a control on selection