Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这可能是一个简单的 C# 问题,但我需要一个解决方案。
我有两种形式form1和form2,其中form1有一个button。点击按钮,我想显示form2。当form2失去焦点时,我想隐藏它(form2)。我怎样才能做到这一点?我试图订阅form2的LostFocus事件,但它不起作用。
请帮我解决一下这个。
注意——我使用 .Net 2.0
使用Deactivate事件处理程序
Deactivate
如果我理解您的问题,我认为您实际上想要捕获停用。主窗体内的按钮处理程序:
private void button1_Click(object sender, EventArgs e) { Form childForm = new Form(); childForm.Deactivate += delegate { childForm.Close(); }; childForm.Show(); }