Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB
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 27-Jan-10 9:26am
Edited 27-Jan-10 11:05am
v2
Rate this: bad
good
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
            LockWindowUpdate(Me.Handle.ToInt32)
 
            'Perform update or change to text here

            'Unlock the window to resume painting
            LockWindowUpdate(0)
   
End Sub
 
Hope this helps.
  Permalink  
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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.
  Permalink  
v2
Rate this: bad
good
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)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 28 Jan 2010
Copyright © CodeProject, 1999-2014
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