I have a rich text box(richTextBox1
) in my program as shown bellow. But when I right click on it, it doesn\'t pop up a “copy, cut, past” window. Can you please tell
I think the solution provided by Thilina H is excellent except few bugs.
MouseUp event causes the right click to start after second click. I recommend using MouseDown event instead of MouseUp event.
I tested secondly provided CopyAction method. In my case CopyAction method didn't copy enter characters. I had to edit the code like this:
Clipboard.SetText(richTextBox1.SelectedText.Replace("\n", "\r\n"));
When richTextBox1.SelectedText is empty the program showed an exception. I simply edited the CopyAction method shown by below to fix the issue.
if (chatBox.SelectedText != null && chatBox.SelectedText != "")
{
Clipboard.SetText(richTextBox1.SelectedText.Replace("\n", "\r\n"));
}
Happy Coding!