Reputation: 908
I have a textbox
, textbox1
, whose ReadOnly
property is set to true. It is somewhat like an on-screen keyboard. When the user presses a button, I can add characters by using:
Textbox1.Text = Textbox1.Text & A
But, when the user wants to remove the text, which should work exactly like the Backspace key, the last character should be removed from the textbox
.
I am ready to give up normal textbox
and use richtextbox
if there is any way ahead with the rich one.
How to remove last character of a textbox with a button?
Upvotes: 1
Views: 16409
Reputation: 11
The above functions such as Substring
and Remove
are not executed in Visual Basic 6 (or earlier versions). I recommend to use Mid
function.
For instance,in this example last character of Hello
is deleted and rest of word is saved in Text1
Text1=Mid("Hello",1, Len("Hello") - 1)
and result is Text1=Hell
Upvotes: 0
Reputation: 1002
The previously suggested SubString
method is what I would have posted too. However, there is an alternative. The Remove
method works by removing every character after the given index. For instance:
TextBox1.Text = Textbox1.Text.Remove(TextBox1.Text.Length - 1)
Upvotes: 5
Reputation: 43743
You can use the SubString
method to get all but the last character, for instance:
TextBox1.Text = TextBox1.Text.SubString(0, TextBox1.Text.Length - 1)
Upvotes: 2