如何获取和设置的WPF文本框的当前光标位置 [英] how to get and set current cursor position of WPF textbox
问题描述
我想从一个WPF文本框当前光标位置。如果文本框
包含文本阿布舍克
键,光标后的 ABHI
然后我想该索引,以便以后有问题地清除文本框,并指派其他一些或相同的文字后成问题,我想刚过4个字符,使光标闪烁。
I want to get the current cursor position from a WPF TextBox. If a TextBox
contains text abhishek
and cursor is blinking after abhi
then i want that index, so that later after clearing textbox problematically and assigning some other or same text problematically i want to make the cursor blink just after 4 characters.
我试图获取光标位置,
_tempFuncName = txtFunctionName.Text;
_cursorPosition = txtFunctionName.SelectionStart;
_selectionLength = txtFunctionName.SelectionLength;
和调回从其他事件这样的一些后期阶段,
And set back at some later stage from other event like this,
txtFunctionName.Text = _tempFuncName;
txtFunctionName.SelectionStart = _cursorPosition;
txtFunctionName.SelectionLength = _selectionLength;
下面突出的变量是页面级变量。
Here underscore variables are page level variables.
这code不工作。有一些其他的方法呢?
This code is not working. Is there some other approach?
推荐答案
您可以用文本框caretIndex属性发挥
You can play with caretindex property of a text box
//You can set this property on some event
NumberOfDigits.CaretIndex = textbox.Text.Length;
这篇关于如何获取和设置的WPF文本框的当前光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!