我正在尝试使用这个函数:
private void IDCustTextBox_LostFocus(object sender, System.EventArgs e)
{
if (CustName.Text == "abc")
MessageBox.Show("Error");
}当我在CustName文本框中键入abc,然后离开文本框时,我没有收到任何消息。在textbox属性中,我可以看到"textbox.Changed“正在使用事件LostFocus。
如何才能让它显示上面的错误消息?
发布于 2013-04-11 13:54:45
属性窗口中没有textbox的LostFocus事件,如果要使用此事件,则必须添加事件处理程序,属性窗口中有textbox leave事件,使用方法如下:
private void textBox1_Leave(object sender, EventArgs e)
{
// do your stuff
}要添加事件处理程序,您需要编写以下代码:
textBox1.LostFocus += new EventHandler(textBox1_LostFocus);然后您可以使用它,如下所示:
private void textBox1_LostFocus(object sender, EventArgs e)
{
// do your stuff
}发布于 2013-04-11 13:59:35
您需要让字段知道有一个用于事件LostFocus的处理程序
因为这是not part of the properties window,所以您需要像这样附加处理程序
CustTextBox.LostFocus += new EventHandler(IDCustTextBox_LostFocus);https://stackoverflow.com/questions/15941562
复制相似问题