许多文本框的一个mousedown事件。 [英] one mousedown event for many textboxes.
本文介绍了许多文本框的一个mousedown事件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含5个文本框的类。对于所有这些,默认值是
在此输入。我想为所有这些事件做一个mousedown事件,使文本框清晰()。当我为该类创建许多对象并将其添加到表单时会有很多事件。
我怎样才能用单个。
解决方案
您只需为所有textBox订阅相同的事件委托方法。
this .textBox1.MouseDown + = new System.Windows.Forms.MouseEventHandler( this .textBox_MouseDown);
this .textBox1.MouseDown + = new System.Windows.Forms.MouseEventHandler(此跨度> .textBox_MouseDown);
private void textBox_MouseDown( object sender,MouseEventArgs e)
{
((TextBox)sender).Clear()
}
< blockquote>如果这些是单行文本框,您只需使用我的 CueProvider [ ^ ]课程。
/ ravi
I have a class that contains 5 textboxes. For all of them, the default value is
"Type Here". I want a single mousedown event for all of them that makes the textboxes clear(""). When I create many object for that class and add it to the form there will be many events.
How can I do that with single.
解决方案
You can simply subscribe the same event delegate method for all the textBoxes.
this.textBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox_MouseDown); this.textBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.textBox_MouseDown); private void textBox_MouseDown(object sender, MouseEventArgs e) { ((TextBox)sender).Clear() }
If these are single line text boxes, you could simply use my CueProvider[^] class.
/ravi
这篇关于许多文本框的一个mousedown事件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文