I am trying to remove characters from current cursor position to start of the string. It's working fine in simple TextBox
if (e.KeyCode == Keys.F2)
{
int LineNumber = txtDescription___.GetLineFromCharIndex(txtDescription___.SelectionStart);
txtDescription___.Text = txtDescription___.Text.Remove(0, txtDescription___.SelectionStart - 0);
}
But when I am trying to execute this code with RichTextBox
it works on Text not on RTF and removes all styles. So I tried this code
if (e.KeyCode == Keys.F2)
{
int LineNumber = txtDescription___.GetLineFromCharIndex(txtDescription___.SelectionStart);
txtDescription___.Rtf = txtDescription___.Rtf.Remove(0, txtDescription___.SelectionStart - 0);
}
Now It's showing the following error
File Format is not valid
Can someone suggest me. How can I perform same code with RTF?
CodePudding user response:
Try the below code,
if (e.KeyCode == Keys.F2)
{
int began = rtbDescription___.SelectionStart;
rtbDescription___.SelectionLength = began;
rtbDescription___.SelectedText = "";
}