I want to know how to get the latest char written in TextBox. It does not mean the last of the string. For instance, I write this :
This i a test.
But I forgot 's', so I move my finger to the 'i' and I add the 's' :
This is a test.
So, how can I get the 's' ?
I want to get it in char or string, but I don't know how to do...
I hope it is clear.
If you want to get the last written character, then subscribe TextBox to the KeyDown event:
C#:
textBox.KeyDown += textBox_KeyDown;
XAML:
<TextBox x:Name="textBox" KeyDown="textBox_KeyDown" />
Then:
private void textBox_KeyDown(object sender, KeyEventArgs e)
{
/* e.Key contains the keyboard key associated with the event. */
}
If you want to get the index of the last written character, then this is more complicated. One of the solution could be tracking the mouse position and cursor in the TextBox
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With