I want to close a System.Windows.Forms.Form if the user clicks anywhere outside it. I\'ve tried using IMessageFilter, but even then none of the messages are passed to PreFi
If it is a child form in an MDI application, you could trap the click in the parent form, otherwise the solution will be messy.
I am not convinced what you suggest represents intuitive UI behaviour anyway. Are you sure that is the best design?
this is simple :
private void button1_Click(object sender, EventArgs e)
{
Form f = new Form();
f.LostFocus +=new EventHandler(f_LostFocus);
f.Show();
}
void f_LostFocus(object sender, EventArgs e)
{
Form f = sender as Form;
f.Close();
f.Dispose();
}