Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the latest char written in textbox?

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.

like image 872
TDK Avatar asked Feb 18 '13 14:02

TDK


1 Answers

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.

like image 184
Ryszard Dżegan Avatar answered Oct 02 '22 07:10

Ryszard Dżegan