softtouch 9 Posted October 21 Lets say I have a modal form , which I display with myform.ShowModal; How can I close this form when the user click outside the form? The form wont have a caption, and is just showing a listview and no buttons. The user can click an entry in the listview, and the form close. But the form should also close when the user click outside the form. Share this post Link to post
Remy Lebeau 1392 Posted October 21 26 minutes ago, softtouch said: How can I close this form when the user click outside the form? You can call the form's Close() method, or set the form's ModalResult property, in the form's OnDeactivate event. Share this post Link to post
Mark- 29 Posted October 21 10 minutes ago, Remy Lebeau said: You can call the form's Close() method, or set the form's ModalResult property, in the form's OnDeactivate event. I know that works for non modal forms, never tried with modal forms. Just tried with 10.2 and OnDeactivate is not called with a modal form, unless I am doing something wrong. Share this post Link to post
Anders Melander 1782 Posted October 21 2 hours ago, softtouch said: How can I close this form when the user click outside the form? You need to capture the mouse in order to receive messages for mouse activity outside the form. See also: SetCapture You should be able to figure it out with that info. Share this post Link to post
Remy Lebeau 1392 Posted October 21 2 hours ago, Mark- said: I know that works for non modal forms, never tried with modal forms. Just tried with 10.2 and OnDeactivate is not called with a modal form, unless I am doing something wrong. Sorry, I meant the TApplication(Events).OnDeactivate event, not the form's OnDeactivate event. You can't click on another form in your app since it has been disabled by the modal form. But, if you click outside of the app then the modal form will lose focus, triggering the TApplication(Events).OnDeactivate event. You can then close the modal form. Share this post Link to post
Mark- 29 Posted October 21 2 hours ago, Remy Lebeau said: Sorry, I meant the TApplication(Events).OnDeactivate event, not the form's OnDeactivate event. You can't click on another form in your app since it has been disabled by the modal form. But, if you click outside of the app then the modal form will lose focus, triggering the TApplication(Events).OnDeactivate event. You can then close the modal form. Thanks. Share this post Link to post