在文本框中单击? [英] click in the Textbox?

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

问题描述

我可能会出现一个简单的问题,但事实并非如此.我想在winforms的文本框中捕获click事件.单击后,我将鼠标停留在此处,但将光标的位置以编程方式移动到了文本框的开头.我尝试单击和单击鼠标,输入鼠标进入文本框的事件,但没有帮助. plz指南.

Hi I might appear a simple questions but it is not as. I want to capture a click event in the textbox in winforms. After click I let my mouse stuck there but move position of the curosr to the start of the textbox programmatically. I have tried click and Mouse click, enter mouse enter event of textbox but no help. plz guide.

推荐答案

嘿,生气的年轻人...

抱歉,无法及时回复.


Hey angry young man...

sorry for late reply..


public Form1()
{
    InitializeComponent();
    textBox1.Text = "shemeer"; // setting a default value
    textBox1.GotFocus += new EventHandler(textBox1_GotFocus); // add the eventhandler for GotFocus..this is not available in the property/event window
}

private void textBox1_GotFocus(object sender, EventArgs e)
{
    textBox1.Select(0, 0); //setting cursor to the begining just after getting focus
}

private void textBox1_MouseClick(object sender, MouseEventArgs e)
{
    textBox1.Select(0, 0);//setting cursor to the begining  on a mouse click

}




希望这能解决您的问题....谢谢




I hope this will resolve your problem.... thanks


该事件称为"Enter".
在代码的早期位置,请订阅活动:
The event is called "Enter".
Somewhere early in your code, subscribe for the event:
myTextBox.Enter+=new EventHandler(myTextBox_Enter);


在事件处理程序中,例如:


In the event handler, do e.g:

TextBox aTextBox = sender as TextBox;
aTextBox.SelectionStart=0;
aTextBox.SelectionLength=0;




在文本框的Click事件中,输入:

TextBox1.Focus();

问候,
Raghu ...
Hi,

In Click event of text box, write:

TextBox1.Focus();

Regards,
Raghu...


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

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