文本框SelectionStart,选定结束和插入符(光标)位置 [英] Textbox SelectionStart, SelectionEnd and Caret (Cursor) Position

查看:3777
本文介绍了文本框SelectionStart,选定结束和插入符(光标)位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是很简单的。

我有一个WinForm,文本=ABCDEFGH的文本框。我需要选择BCD,离开工字钢(光标,插入符闪烁'|')的'A'和'B'的权利。设置SelectionStart = 1和SelectionLenght = 3不工作,我不明白。

I have a textbox on a WinForm, Text = "ABCDEFGH". I need to select "BCD" and leave the I-Beam (cursor, caret, blinking '|') right between the 'A' and the 'B'. Setting SelectionStart = 1 and SelectionLenght = 3 doesn't work and I can't figure it out.

推荐答案

您需要设置在 SelectionLength 0为的在文档说。

You need to set the SelectionLength to 0 as noted in the documentation.

您可以通过编程设置移动文本框中插入符
的SelectionStart要在其中
插入符号移动到与SelectionLength属性设置为零(0)。

You can programmatically move the caret within the text box by setting the SelectionStart to the position within the text box where you want the caret to move to and set the SelectionLength property to a value of zero (0).

如果该问题是的 BCD 的其实是在选择,但你希望光标之前的感动背部b 这里。

If the issue is that BCD is in fact selected, yet you want the cursor moved back before the B I don't believe you will be able to do that via the framework properties since selecting text will move the cursor to the end of the text. You would need to use coordinates and a native interop as noted here.

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetCaretPos(out Point lpPoint);

您可以再调用的 SetCaretPos

这篇关于文本框SelectionStart,选定结束和插入符(光标)位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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