remove characters from TextBox

luri

Newcomer
Joined
Oct 17, 2005
Messages
2
Hi,
I would like in some event to delete few characters from my TextBox.
I don't want to do txtBox.Text = newText since it has bad performace (my text might be big).

I would like to "send" to the Text the character 8 (backspace) the required times.

How can I do that?
 
I'm not entirely sure if I understood you but it sounds like you wish to remove a character although the Backspace key has been pressed. Since pressing backspace in a textbox will achieve this anyway i'm assuming you are creating your own. Either way if I understand you correctly you can use this.

Code:
textBox1.Text =  textBox1.Text.Remove(textBox1.Text.Length - 1, 1);

Obviously that will delete the last char, you could easily modify it to delete a different char or strech or chars. As for whether this is any more effecient than what your currently trying I don't know. But as far as I know theres no easy way of removing a char without assigning a new string to the Text property.
 
Thanks, but I'm not sure it helps me.
You see, assigning a new String to the text box cause the text box to blink (refresh) when it contains a big string.
Maybe there is a way to avoid this blibking?!
Thanks.
 
Well as far as I know the strings in .Net are immutable, which means they can't be changed only reassigned, this being said I feel your best option is to look into preventing the flicker. You might get more help if you explain exactly how much text your talking about and why your working with such big strings.
 
I guess your problem is not really the Text but the paint process of that box.

I would try two possibilities

1. Override the OnPaint() event in a derived textbox and control when to paint how much. So actual text is held in the Text property but you paint only that is visible

2. Create a custom/owner drawn control
 
Back
Top