# Making a windows form totally modal, preventing Esc-button ?

**URL:** <https://forum.servoy.com/t/making-a-windows-form-totally-modal-preventing-esc-button/19042>\
**Category:** Classic Servoy\
**Created:** [November 2, 2016, 9:55pm UTC](https://forum.servoy.com/t/making-a-windows-form-totally-modal-preventing-esc-button/19042 "2016-11-02T21:55:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bernd.N](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@Bernd.N](https://forum.servoy.com/u/Bernd.N)\
**Post date:** [November 2, 2016, 9:55pm UTC](https://forum.servoy.com/t/making-a-windows-form-totally-modal-preventing-esc-button/19042/1 "2016-11-02T21:55:25Z")

</div>

We use a small dialog form to add a simple record, which resides in a floating windows form (smart client).  
We use the dialog framework for that task which works very well:

> **[Overview - Dialogs module - ServoyForge](https://www.servoyforge.net/projects/mod-dialog)**
>
> Redmine

We need to make that dialog form totally modal, and took already the windows header away, so that the user could not close the form with the X on right upper side.  
Now we have just one issue left we could not solve:  
The user is still able to close that window with the Escape button.

Is there a way to prevent this?

I guess this is a generic question for all windows forms, not only for this dialog framework from Servoy Forge:  
How to disable the escape button for forms in windows…

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [November 2, 2016, 10:08pm UTC](https://forum.servoy.com/t/making-a-windows-form-totally-modal-preventing-esc-button/19042/2 "2016-11-02T22:08:32Z")

</div>

Hi Bernd,

you can prevent closing any dialog by returning ‘false’ in the onHide function of the form which you are showing in the dialog.

So I suggest you set a formVariable with a value at the onShow of the form, ie. allowHide = false;  
When the user is pressing the buttons you want him to press, you can set the allowHide variable to true.

In the onHide function you’ll need to return allowHide.

```auto
function onHide(event) {
	
	//just any code you want to do at onHide
	
	return allowHide;
}

```

---

<div class="post-metadata">

**Author:** ![Bernd.N](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@Bernd.N](https://forum.servoy.com/u/Bernd.N)\
**Post date:** [November 2, 2016, 11:12pm UTC](https://forum.servoy.com/t/making-a-windows-form-totally-modal-preventing-esc-button/19042/3 "2016-11-02T23:12:59Z")

</div>

Hi Marc,  
we tried that approach today and somehow it did not work.  
But after you suggested it again, I tried again and now it works.  
Thank you!

---

<div class="post-metadata">

**Author:** ![patrick](https://avatars.discourse-cdn.com/v4/letter/p/b2d939/32.png) [@patrick](https://forum.servoy.com/u/patrick)\
**Post date:** [November 3, 2016, 8:49am UTC](https://forum.servoy.com/t/making-a-windows-form-totally-modal-preventing-esc-button/19042/4 "2016-11-03T08:49:44Z")

</div>

You could also have a look at the svyCustomDialogs scope on github ([https://github.com/Servoy/svyUtils/wiki/Custom-Dialogs](https://github.com/Servoy/svyUtils/wiki/Custom-Dialogs)). It can replace the mod\_dialog feature wise and allows you to easily build any kind of simple dialog with any number of components in it (like a simple change password dialog). And a CustomDialog has an onClose property that gives you control over the “X”.
