Prevent use of the X to close a window

The need is to prevent users from being able to close a specific window by using the X in the upper right corner and force them to use the native button to move out of that screen (OK for one window, the Save button for the other). I have seen the control to call out the close window function, so does that mean there’s a way to prevent that action as well?

I am admittedly not a programmer, so apologies if this is something easy for some.

Are you referring to a specific form or modal window?

When you say “force them to use the native button to move out of that screen (OK for one window, the Save button for the other)”, do those windows also have other buttons(like “Cancel” or “Don’t Save”) ?

In this particular example, it’s the Serial Number select screen in End Activity. That screen has “OK” and “Cancel” as options. I want the users to be forced to use one of these buttons to close the form and NOT be able to click the X. Clicking on the X will keep the SN selected (like OK) instead of clearing it out (like Cancel). This allows our users to bypass some logic we have in place.

One option is to complete remove the control box (minimize, Maximize and close)

in the InitializeCustomCode() method add this.PartForm.ControlBox = false;

replace PartForm with the form you are using

Should this logic be moved server side?

The real annoying part of this is I have a BPM in place here that correctly pops an error message if they hit OK, and if they click Cancel all is well. However, clicking close, for some reason, keeps the serial number in place as selected and doesn’t behave like cancel does. I tried setting the serial number to blank in the BPM but that didn’t seem to work. I’ll try that again in case I missed something before.

Oooooh, I’m definitely going to try this. We have an Insp Plan configurator that we want to prevent users from leaving the screen before filling in all data, so this could be a winner.

And to make sure I know what I’m trying to do, can I put this into the Form Event Wizard on Load?

Thanks!

This worked like a charm. Add the code to the Form Event Wizard at Load, changed the form name and viola! This will help in multiple areas!

What about ALT+F4

Until Kinetic. :thinking:

I’m not super concerned about our operators knowing hot keys, but would there be a way to suppress that as well?

We can cross that bridge when we get there. Maybe the challenge I’m fighting will be resolved when we upgrade or a new tool will help me better close this off (ie. Functions).

1 Like

Can you hook to the closing form event to cancel it?