Click here to Skip to main content
15,896,313 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anybody tell me a good way to backspace via code in a multiline text box in Visual basic 2008?

The current methods I have cause the text box to blink / shutter and it makes it look glitchy. I need a method that doesn't rewrite the string by doing a string = string.substring(0, string.length - 1)


UPDATE:

This is a terminal program much like hyperterminal, or putty...
The multi-line text box I am using has a keypress function that sends the ascii character for the key to a serial port. From the serial port you get the character back, and any other data the serial port sends as part of its processing of that character. Once the program receives feedback from the serial port, it prints it to the same multiline text box the key was pressed from to start with.
The terminal sends backspace characters chr(8).
If i print them directly, I get a square (unsupported character).
I want to interpret the character code and backspace the last character.
If I use sendkeys, i would loop myself a bunch of backspaces until infinity I believe.
Posted
Updated 27-Jan-10 10:05am
v2

You might want to research LockWindowUpdate. It lets you lock the window to stop the form from painting, then you can use it after you're done changing the textbox to unlock the form and continue painting. I've used it in the TextChanged event, so I'm not sure how it works if you are using KeyUp, KeyDown, or KeyPress.

Here are some articles [^]that use it.


VB
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hWnd As Integer) As Integer

Private Sub richtextbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
           Handles txtMyRichtextbox.TextChanged
            'Lock the window from painting to prevent flicker
            LockWindowUpdate(Me.Handle.ToInt32)

            'Perform update or change to text here

            'Unlock the window to resume painting
            LockWindowUpdate(0)
   
End Sub


Hope this helps.
 
Share this answer
 
Jaike - you posted exactly the code that he said doesn't work because it flickers. No, I doubt that helps the OP.
 
Share this answer
 
Not quite sure if I see the real issue here....

Does this help

TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)
 
Share this answer
 
You could perhaps use SendKeys to send backspace ?

You can replace the chr(8) with Keys.BackSpace. You can also set the selected area of the textbox, there's a selection start and selection end property, I believe. If you were to select the characters that had been backspaced over, when you output a new character, it will erase what was selected.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900