您可以尝试在触发按钮逻辑之前跟踪是否发生了丢失焦点逻辑。无论如何,您不应该直接在处理程序中直接使用代码。你可以这样做:
public partial class Form1 : Form
{
private Boolean _didLostFocusLogic;
public Form1()
{
InitializeComponent();
}
private void textBox1_Leave(object sender, EventArgs e)
{
LostFocusLogic();
}
private void button1_Click(object sender, EventArgs e)
{
ButtonClickLogic();
}
private void LostFocusLogic()
{
/* Do stuff */
_didLostFocusLogic = true;
}
private void ButtonClickLogic()
{
if (!_didLostFocusLogic)
LostFocusLogic();
_didLostFocusLogic = false; // Reset for next time.
/* Do stuff */
}
}