[英]How to set cursor position in textBox on button click event using c#?
I have two text boxes
and a button in windows form app
using c#
. 我在
windows form app
使用c#
有两个text boxes
和一个按钮。
when i enter text in txtbox1
and send that text to txtbox2
on button click event
, the cursor also goes to txtbox2
. 当我在
txtbox1
输入文本并将button click event
上的文本发送到txtbox2
时,光标也将移至txtbox2
。
My requirement is when i send data from textBox1
to textBox2
on buton click event the cursor should remain in textBox1
. 我的要求是,当在click事件上将数据从
textBox1
发送到textBox2
时,光标应保留在textBox1
。
In the buttonClick event just add at the end: 在buttonClick事件中,只需在末尾添加:
textBox1.Focus();
Any reasons why dont set cursor position manually after the click event? 有什么原因导致单击事件后不手动设置光标位置?
Cursor.Position = new Point(MyFirstTextbox.Location.X -5, MyFirstTextbox.Location.Y -5);
Also Control.Focus() helps you. Control.Focus()也可以帮助您。
On button click write at last: 在按钮上单击最后写入:
textbox1.focus()
focus
is the method you need to use. focus
是您需要使用的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.