Mouse hit test for outside form area

  • Thread starter Thread starter glerner
  • Start date Start date
G

glerner

I have a form (no titlebar) with only the MonthCalendar control. If
the user clicks anywhere outside of the window (and the area within
parent window) I want to close the window.

How can I do this?

Thanks,
Glenn
 
Hi glerner,

You can use the LostFocus event to know when the user wants something else
to be focused (ie clicks outside the form).

protected override void LostFocus(EventArgs e)
{
this.Close();
}

Happy coding!
Morten
 
Thanks Morten,

I don't see LostFocus event on Properties/Event window. Is this an
event I have to add manually? Why don't all possible events show up
in Properties window?

Thanks.
Morten Wennevikwrote: Hi glerner,

You can use the LostFocus event to know when the user wants something else
to be focused (ie clicks outside the form).

protected override void LostFocus(EventArgs e)
{
this.Close();
}

Happy coding!
Morten
http://www.opera.com/m2/
 
glerner said:
Thanks Morten,

I don't see LostFocus event on Properties/Event window. Is this an
event I have to add manually? Why don't all possible events show up
in Properties window?

Thanks.
Morten Wennevikwrote: Hi glerner,

You can use the LostFocus event to know when the user wants something else
to be focused (ie clicks outside the form).

protected override void LostFocus(EventArgs e)
{
this.Close();
}

Happy coding!
Morten
http://www.opera.com/m2/



----------------------------------------------------------

----------------------------------------------------------
color]

Micrisoft discourages the use of GotFocus and LostFocus, except under
specific conditions, hence they are not shown in the event browser. The .NET
help docs state:

----------------------
Note The GotFocus and LostFocus events are low-level focus events that are
tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically, the
GotFocus and LostFocus events are only used when updating UICues. The Enter
and Leave events should be used for all controls except the Form class,
which uses the Activated and Deactivate events. For more information about
the GotFocus and LostFocus events, see the WM_SETFOCUS and WM_KILLFOCUS
topics in the Keyboard Input Reference section of the Platform SDK
Documentation in the MSDN Library.
 
Back
Top