日期:2014-05-18  浏览次数:20666 次

如何触发这个事件方法???
private   void   textBox1_Enter(object   sender,   System.EventArgs   e)
                {
                        if   (textBox1.Text   !=   String.Empty)
                        {
                                textBox1.ForeColor   =   Color.Red;
                                textBox1.BackColor   =   Color.Black;
                                textBox1.Select(textBox1.Text.Length,   0);
                        }
                }

如何触发这个事件?
this.textBox1.Dispose   +=   new   System.EventArgs(this.textBox1_Enter);
这个地方怎么写???

------解决方案--------------------
private void textBox1_Enter(object sender, System.EventArgs e)
{
if (textBox1.Text != String.Empty)
{
textBox1.ForeColor = Color.Red;
textBox1.BackColor = Color.Black;
textBox1.Select(textBox1.Text.Length, 0);
}
}
改为
public void textBox1_Enter(object sender, System.EventArgs e)
就可以拉,时间声明放到页面加载中
------解决方案--------------------
不懂楼主的意思,如果是想响应textBox的回车事件,应该是KeyPress事件,如
private void textBox1_KeyPress(object sender, System.EventArgs e)
{
if (e.KeyChar == (char)13)
{
// 业务处理
}
}
请问楼主到底是想在哪里响应回车事件?
------解决方案--------------------
楼主要是想触发回车事件的话,我的习惯都是在KeyPress事件中实现。

在事件中可以用if(e.KeyChar == (char)13)来作为判断条件就可以了。