Windows Develop Bookmark and Share   
 index > Windows Forms General > Copy and Paste Keyboard Shortcuts won't work in Rich Text Box.
 

Copy and Paste Keyboard Shortcuts won't work in Rich Text Box.

I have a rich text box that was allowing me to use CTRL C an CTRLV to copy and paste into and out of it.. and all of a sudden it just stopped working...

so I made a context menu to have the Copy/Cut/Paste options in it, and assigned short cuts to them... but it sitll won't work.

why is the Copy/Cut/Paste shortcuts disabled now? did I click something by accident?

djanim8  Tuesday, March 18, 2008 10:07 PM

Here is what i presume might have happened, that's stopping your Rich text box from not responding to Ctrl+C and Ctrl+V shortcuts.

1. You may have assigned the shortcut keys to some menu options (for e.g. you may have a menu option like edit, with the short cut pointing to Ctrl+c key stroke)

2. You may have assigned the Cut-Copy-paste shortkeys to the appropriate menu options, but might not have provided a corresponding Cut-Copy-Paste implementation for the Menu handlers.

In your case, i think the context menu has the short-cut keys assigned to them, but you might not have provided an implementation for the context-menu handlers, corresponding to those Short-cut keys.

Check the various shortcut key bindings that you may have assigned to various menu options, and try removing them or provide an alternate implementation.

Ramses2  Sunday, June 15, 2008 6:54 AM
djanim8 wrote:

I have a rich text box that was allowing me to use CTRL C an CTRLV to copy and paste into and out of it.. and all of a sudden it just stopped working...

so I made a context menu to have the Copy/Cut/Paste options in it, and assigned short cuts to them... but it sitll won't work.

why is the Copy/Cut/Paste shortcuts disabled now? did I click something by accident?

You don't have to use any shortcustto copy or paste. If you have a context menu (I think it is better to use ContextMenuStrip, but it is a matter of preference) you can simply use Rtf.Copy () or Rft.Paste ( ); to copy and paste. Obviously these two methods should be positioned in corresponding event delegates.

In order to Copy you have to make sure that a piece of richTextBox1.Text has been selected.

The reason why the shortcust do not work may be something like the RichTextBox losing focus. You should make sure the focus is kept.

AlexBB - Vista Ult64 SqlSer64 WinSer64  Tuesday, March 18, 2008 11:56 PM
Did you add handlers for KeyDown or KeyPress events? If so, you may want to make sure that certain key combinations are allowed to pass through your handlers and on to the default handlers for the RichTextBox.

veryed  Wednesday, March 19, 2008 12:39 AM
I do have one on the KeyUp handler.. how do I make sure key combinations are allowed?

and p.s. this has always been there since day one, and the CTRL C and CTRL V worked on the first release, no other changes were made to the RichTextBox since then.. its really weird.

djanim8  Wednesday, March 19, 2008 12:27 PM

Still can't get this to work.. I have NO idea why.. I've removed all the KeyUp handler event stuff, made it a "TextChange" event handler, and its stilll not working.

don't really get this...

djanim8  Tuesday, March 25, 2008 1:29 PM

Here is what i presume might have happened, that's stopping your Rich text box from not responding to Ctrl+C and Ctrl+V shortcuts.

1. You may have assigned the shortcut keys to some menu options (for e.g. you may have a menu option like edit, with the short cut pointing to Ctrl+c key stroke)

2. You may have assigned the Cut-Copy-paste shortkeys to the appropriate menu options, but might not have provided a corresponding Cut-Copy-Paste implementation for the Menu handlers.

In your case, i think the context menu has the short-cut keys assigned to them, but you might not have provided an implementation for the context-menu handlers, corresponding to those Short-cut keys.

Check the various shortcut key bindings that you may have assigned to various menu options, and try removing them or provide an alternate implementation.

Ramses2  Sunday, June 15, 2008 6:54 AM

You can use google to search for other answers

Custom Search

More Threads

• Unhappy with how the form loads.
• Slower paint on higher configuration
• Changing Border Color of a Button every 3 seconds
• How to delete copy of ListViewItem
• System.NullReferenceException: Object reference not set to an instance of an object.
• problem with ToolStripMenuItems
• Setup Project problems
• Creating and Adding text to tables in word
• Multi-Line Text Header in DataGrid?
• Cannot cast object of type X to Type X