I’m looking to customise a Rich Text Box control on my Windows Form Application. The RichTextbox will be used for inputting text data that once completed, will be sent via SMS text message.
The requirements are that the text can’t have any line breaks in as some of the older mobile phones don’t display the information correctly and it loses its formatting.
What I need to be able to do is catch the clipboard data before its pasted into the RTB and customise its formatting, e.g remove line breaks.
I have found an example on here that’s got this working to an extent, but takes away being able to paste into other controls :-
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if((keyData == (Keys.Control | Keys.V)))
{
IDataObject iData = Clipboard.GetDataObject();
if (iData.GetDataPresent(DataFormats.Text))
{
string contents = Clipboard.GetText().Replace("\r\n", " ");
Clipboard.SetData(DataFormats.Text, contents);
richTextBox1.Paste();
}
return true;
}
else
{
return base.ProcessCmdKey(ref msg, keyData);
}
}
Does anyone know how I should be doing this please?
You need to inherit from RichTextBox, and add the custom processing as you described yourself; you can also set the original data back into the clipboard, to be able to paste it into other controls(in the original form):