Programmatic Delete of last char in a Richedit

  • Thread starter Thread starter ozbear
  • Start date Start date
O

ozbear

The title says it all. Since a Richedit control doesn't understand a
backspace character ('\b', or 0x08) when I receive one I need to
programmatically delete the last character from the Richedit control.
This is a WinForms application, not a webform.

I have tried...
re.SelectionLength = 1;
re.SelectionStart = re.Textlength-1;
re.SelectionText = ""; // empty string

but that doesn't seem to delete the last character. It stays there.

Any advice from anyone?

Oz
 
ozbear,

This might be overkill, but you could always set the text like this:

re.Text = re.Text.Substring(0, re.Text.Length - 1);

If you have a lot of text though, I can see how that would be very
inefficient.

Hope this helps.
 
It isn't the amount of text, so much as the amount of screen
disruption that occurs. When one sets the Text like you suggest,
what effectively happens is a Clear followed by an AppendText
of the string whch puts you pack up at the top of the text and
you have to go thru scrolling up to the end of the text, restoring the
caret to the end and so forth.

There must be an easier way.

By the way...is the way I originally posted *supposed* to work?

Regards, Oz

ozbear,

This might be overkill, but you could always set the text like this:

re.Text = re.Text.Substring(0, re.Text.Length - 1);

If you have a lot of text though, I can see how that would be very
inefficient.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


ozbear said:
The title says it all. Since a Richedit control doesn't understand a
backspace character ('\b', or 0x08) when I receive one I need to
programmatically delete the last character from the Richedit control.
This is a WinForms application, not a webform.

I have tried...
re.SelectionLength = 1;
re.SelectionStart = re.Textlength-1;
re.SelectionText = ""; // empty string

but that doesn't seem to delete the last character. It stays there.

Any advice from anyone?

Oz
 
<snip>
Breakthrough...

My problem was (alas!) that I had the ReadOnly property for my
RichEdit set to true.

Note to the Universe...set Readonly to false if you are going to
try and delete text, programmatically or otherwise.

Oz
 
Back
Top