在文本框中设置光标 [英] set cursor in textbox

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

问题描述

你好,

我创建了1个应用程序.其中必须有一个文本框.当我键入第一个字符时它没有被选择.事实上我不想选择它.在它之后,当我在第一个字母后键入第二个字母时要突出显示它.我突出显示它.然后我想输入第三个字母,然后总是用第二个位置替换.我不想那样.当我按右键时,只有我可以在文本框中添加第三个字母.但是evrytime按righ键.

所以我的主要问题是键入任何字符后如何自动设置光标位置?以及如何选择/突出显示除第一个字符以外的所有其他字符?

Hello,

I create 1 application.In that have to take one textbox.when i type 1st character then its not get select.infact i don''t want to selct it.after it when i type 2nd letter after 1st letter want to highlight it.i highlight it.then whane i type 3rd letterthen it alwys replace by 2nd position.I don''t want like that.when i press right key then only i can add 3rd lette r in textbox.but evrytime press righ key.

So my main question is that how to set cursor position automatically after type any character? and also how to select/highlight this all characters except 1st one?

推荐答案

对于Windows.Forms,请使用TextBox.Select(Int32,Int32) [
For Windows.Forms use TextBox.Select(Int32, Int32)[^] method.


如果要突出显示文本的一部分TextBox而不是选择它,您需要一个专门的textbox控件.
您也可以尝试以下方法:
用于语法突出显示的彩色文本框 [ ^ ]
制作自己的文本框实现并不容易,因为它依赖于低级api工具-但是您可以从其原始代码开始.
If you want to highlight part of the text in a TextBox rather than selecting it, you need a specialized textbox control.
You also might try this one: Fast Colored TextBox for Syntax Highlighting[^]
It is not easy to make your own textbox implementation, since it relays on low level api tools - but you can start from it''s original code.


在C#中..
在需要的地方写下下面的行
TextBOx1.Focus();
In C#..
write the below line wherever is necessary
TextBOx1.Focus();


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

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