Windows Forms: How to copy paste plain text in RichTextBox in C#
By FoxLearn 3/16/2020 7:12:06 PM 7.07K
This post shows you How to copy paste plain text into a RichTextBox in C# Windows Forms Application.
Dragging a RichTextBox control from your Visual Studio toolbox to your form designer.
By default, Instead of pasting the text with format. We can extract the plain text, then add it into the RichTextBox control.
Clicking on RichTextBox control, then select properties.
Adding a KeyDown event handler allows you to paste text into a RichTextBox control.
private void richTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.Control && e.KeyCode == Keys.V) { richTextBox.Text += (string)Clipboard.GetData("Text"); e.Handled = true; } }
Every time you copy data, it will be stored in the Clipboard. To get plain text to can call GetData("Text") method.
Categories
Popular Posts
Visual Studio: Auto increment version
04/01/2024
What is ARM architecture?
04/01/2024
What Are RESTful Web Services?
02/19/2024