如何获得写在文本框中的最新字符? [英] How to get the latest char written in textbox?

查看:164
本文介绍了如何获得写在文本框中的最新字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何获得写在文本框的最新字符。这并不意味着最后的字符串。
比如,我写这篇文章:

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 :

这IA测试

但我忘了'S',所以我把我的手指'我',我加入'S':

But I forgot 's', so I move my finger to the 'i' and I add the 's' :

这是一个考验。

那么,怎样才能让我的's'?

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.

推荐答案

如果你想获得最后写入字符,然后订阅的文本框的KeyDown 事件:

If you want to get the last written character, then subscribe TextBox to the KeyDown event:

C#:

textBox.KeyDown += textBox_KeyDown;



XAML:

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.

这篇关于如何获得写在文本框中的最新字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆