Click here to Skip to main content
13,053,026 members (59,895 online)
Rate this:
Please Sign up or sign in to vote.
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)


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 27-Jan-10 8:26am
Updated 27-Jan-10 10:05am
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

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.

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
            'Perform update or change to text here
            'Unlock the window to resume painting
End Sub

Hope this helps.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Jaike - you posted exactly the code that he said doesn't work because it flickers. No, I doubt that helps the OP.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Not quite sure if I see the real issue here....

Does this help

TextBox1.Text = TextBox1.Text.Substring(0, TextBox1.Text.Length - 1)

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 28 Jan 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100