Using SendKey within a form to change text

UncleRonin

Well-known member
Joined
Feb 28, 2006
Messages
230
Location
South Africa
Programming Experience
5-10
I have a graphical keyboard where the user clicks a character and it gets added to a textbox. I had homemade code which gets caret positions and selections and pretty much goes nuts... so I decided to use SendKey instead. It all works great except I cannot for the life of me get a BackSpace button to work.

I've tried SendKey.Send("{BACK}") , {BS} and {BACKSPACE} but neither of them work. I've searched all over the place but can't find out why. The textbox gets selected just before SendKey is called yet nothing happens.

Is this some thing to do with SendKey, backspace or am I missing something? Its not a big deal but this is one of those things I HAVE to know for the sake of learning something new. Does anyone have any ideas?
 
When I for example do this (code below) the last character is deleted:
VB.NET:
TextBox1.Focus()
TextBox1.Select(TextBox1.TextLength, 0)
SendKeys.Send("{BS}")
So does this (below), so it shouldn't be much problem using the Select... properties and methods also:
VB.NET:
TextBox1.Select(TextBox1.TextLength - 1, 1)
TextBox1.SelectedText = ""
 
:eek: I found why my Sendkey.Send("{BACKSPACE}") wasn't working... Visual Studio removed the backspace button event handler when I was redesigning the form so the bloody thing wasn't even firing! *falls over* Man is that embarassing!

As far as using Select and SelectedText, its easy if there IS selected text but as soon as the user specifies a different position in the text and there is no actual selected text all hell breaks loose. I haven't been able to find out a way for getting the caret position within the text. Do you know?
 
SelectionStart property
 
Back
Top