BACKSPACE without using the keyboard

  • Thread starter Thread starter Petter Gran via .NET 247
  • Start date Start date
P

Petter Gran via .NET 247

(Type your message here)
First I write "Petter" to a textBox then I want to delete the last r, but instead of deleting the last "r" I get a square box.

How can I delete the last "r" ?

I do not use the keyboard.

this.textBox1.Text = "Petter";
this.textBox1.Text += Convert.ToString('\u0008');


Regards
PetterGran
 
Hi Peter,

All those ASCII codes sucha as Backspace, Bell, LineFeed, etc (codes below
32) are called control symbols. They have some meanings for some character
devices such as printers. The console recognizes some of them as well.
Beside this they are nothing that numbers, which even have no graphical
representation.
Windows' text API doesn't recognizes those codes and because most of the
fonts has no glyphs they are printed as squares.

You can read Text property. Delete the last symbol and returned back.
However it may work ok for small text, but if you have a lot of text in the
text box this would be the slowest method, I believe.

So my suggestion is to use SelectionXXX properties.

int selStart = this.textBox1.TextLength-1;
if(selStart < 0) return;

this.textBox1.SelectionStart = selStart;
this.textBox1.SelectionLength = 1;
this.textBox1.SelectedText="";

This code snippet is not 100% correct it suffers problems when the text ends
with 'EndOfLine' However it can be easily overcome.


--
HTH
Stoitcho Goutsev (100) [C# MVP]


Petter Gran via .NET 247 said:
(Type your message here)
First I write "Petter" to a textBox then I want to delete the last r, but
instead of deleting the last "r" I get a square box.
 
Back
Top