开发者

Close Modal Form when mouse click outside form area

I would like to close a modal form when the user clicks outside (anywhere on the computer desktop) the modal form. How can we do this as a modal form is not mean开发者_运维百科t to lose focus.


You need to hook mouse (and keyboard if required) and capture their events. Then check if the click happened outside the form (and area). If yes, flag a sign which can be read by the model form that it can close down.

Algo:

  1. Hook mouse click event.

  2. When callback function is called, check for the click position - if it's inside your form or not (you might need to translate the locations to Desktop locations - I hope you know how to!)

  3. If the point is outside the form, set a flag (boolean or anything that makes you happy). Make sure the form can read the flag somehow.

  4. Trigger an event for form to capture. In it's handler read the flag status. If true, close/unload the form.

This page will tell you technical details and functions.


I don't think you need to make it modal... then you can take siride's option of closing it on the Deactivate event.

The reason you don't need to make it modal: The first time you display it, it will have the focus and be topmost. Modal prevents you from clicking somewhere else, but you want to be able to click somewhere else... and when you do, the form goes away, so there are no modal needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜