How to update the text from the TextBox control?
Consider a TextBox that already contains the string “Wel”
To insert text in the TextBox, I use:
TextBox1.Text = TextBox1.Text.Insert(3, "come")
And to remove characters from the TextBox:
TextBox1.Text = TextBox1.Text.Remove(3, 4)
But I need to be able to do this:
TextBox1.Text.Insert(3, "come");
TextBox1.Text.Remove(3, 4);
However, this code doesn’t update the TextBox.
It this possible?
Can this be accomplished via the append method?
Textproperty of TextBox is of type string which is immutable it’s not possible to change the existing string.Insert()orRemove()returns a new instance of string with the modification and you will have to assign this new instance back to TextBox’s Text property.There is
TextBox.AppendText()that you might be interested in. It appends text to the end of the string but you cannot do anything likeInsert()orRemove()with it though.EDIT:
for your keypress, you could do something like this