wpf c#中文本框中的光标位置 [英] Cursor position in a text box in wpf c#

查看:661
本文介绍了wpf c#中文本框中的光标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

i在wpf c#windows应用程序中使用Datagrid,我在datagrid wpf中处理文本框事件....当用户在文本框中输入一个键时,将调用change事件。 ..但是在那个事件之后光标的焦点正在丢失......在这种情况下,用户应该再次进入文本框并输入值...任何人都可以建议如何将光标定位在文本框之后string ....我使用跟随代码,光标放在文本框的开头





Hello,
i am using Datagrid in wpf c# windows application, I am handling antext box event in datagrid wpf.... when user enters a key in text box the change event willl be called... But after that event the Focus of the cursor is being lost... in the case again the user should go to the text box and enter the value... Can anyone suggest how to position the cursor in a text box after the string.... I use the followin code where the cursor is placing at the starting of text box


Keyboard.Focus(txtLineItemUnits);







请建议我任何工作代码...... .pls




Please suggest me any working code.... pls

推荐答案

术语插入符号和光标之间的大多数时间都有混淆。光标是鼠标光标,插入符号是文本框内的垂直闪烁条,表示插入点。

您可以通过
There is some mixing up going on in most of times between the terms "caret" and "cursor". Cursor is the mouse cursor, caret is the vertical blinking bar inside the textbox that indicates the insertion point.
You can control caret position (and selection) by
TextBox.SelectionStart

TextBox.SelectionLength

属性。

如果你想在第3个字符集之前移动插入符号

properties.
Example if you want move caret before 3th character set

SelectionStart = 2

SelectionLength = 0





如果你的意思是同时使用鼠标光标和插入符号,那么你可以使用如下代码: br $>




If you mean the mouse cursor and the caret at the same time, then you can use a code like:

// save current cursor position and selection 
        int start = textBox.SelectionStart;
        int length = textBox.SelectionLength;

        Point point = new Point();
        User32.GetCaretPos(out point);

        // update text
        textBox.Text = value;

        // restore cursor position and selection
        textBox.Select(start, length);
        User32.SetCaretPos(point.X, point.Y);


这篇关于wpf c#中文本框中的光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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