private void textEdit1_Leave(object sender, EventArgs e)
{
if (dtPrint.Rows.Count > 0 && company != textEdit1.Text.Trim())
{
if (MessageBox.Show("客户名称不一样,是否取消打印之前录入的运单?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
dtPrint.Clear();
PrintBtn.Visible = false;
print_totalamt = 0.0;
}
}
}private void textEdit1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)//回车
textEdit3.Focus();
}为什么回车会出现两次对话框,如何解决?
{
if (dtPrint.Rows.Count > 0 && company != textEdit1.Text.Trim())
{
if (MessageBox.Show("客户名称不一样,是否取消打印之前录入的运单?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
dtPrint.Clear();
PrintBtn.Visible = false;
print_totalamt = 0.0;
}
}
}private void textEdit1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)//回车
textEdit3.Focus();
}为什么回车会出现两次对话框,如何解决?
这句后面加一句
e.Handled = true;
当你按回车的时候,KeyDown和leave都捕捉到了,所以依此触发,就是2次.
{
if (MessageBox.Show("adfasfdasfd", "adasfd", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
textBox2.Clear();
textBox2.Text = "111";
}
} private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)
{
textBox3.Focus();
} }
当原来的焦点在textBox1上按回车时,才有一个框出来.
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void textBox1_Leave(object sender, EventArgs e)
{
MessageBox.Show("leave");
} private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyValue == 13)//回车
textBox2.Focus();
}
}
}
很明显,你的textEdit3.Focus();又触发了textEdit1_Leave事件~
this.textEdit1.Leave += new System.EventHandler(this.textEdit1_Leave);
注册了几次~
请对您的言行负责,并遵守中华人民共和国有关法律法规,尊重网上道德。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。