在c#中双击光标时,将光标放在文本框中的某个位置 [英] get cursor at a position in atextbox when it double clicked in c#
本文介绍了在c#中双击光标时,将光标放在文本框中的某个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框,里面有一些字符串。当我在里面双击它时,我想把光标放在那个特定位置。我可以这样做吗?
你好,
如果你想得到光标的位置:
private void textBox1_DoubleClick( object sender,EventArgs e)
{
MouseEventArgs mouseEventAgrs =(MouseEventArgs)e;
Point nousePosition = mouseEventAgrs.Location;
}
如果你想把角色放在你双击的位置:
添加:
<前lang =cs> Char c = textBox1.GetCharFromPosition(nousePosition);
如果你想获得所选文字:
string selectedText = textBox1.SelectedText;
等...
Valery。
I have a text box with some string in it. when i double click inside it I want to get the cursor at that particular position .how can i do this.?
解决方案
Hello,
If you want to get the position of the cursor:
private void textBox1_DoubleClick(object sender, EventArgs e) { MouseEventArgs mouseEventAgrs = (MouseEventArgs) e; Point nousePosition = mouseEventAgrs.Location; }
If you want to get the character at the position where you double-clicked:
Add:
Char c =textBox1.GetCharFromPosition(nousePosition );
If you want to get the selected text:
string selectedText = textBox1.SelectedText;
Etc...
Valery.
这篇关于在c#中双击光标时,将光标放在文本框中的某个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文