Close with Class

CloseButton_big2One rule to remember when designing a user interface is to do things in standard ways.

For example, if you want to close a program in Windows, you click the red X button in the upper right-hand corner of the window. Most LabVIEW™ have a tell-tale “Stop” or “Done” button. That always bugs me. Why shouldn’t a LabVIEW program end the same way any other Windows program ends?

Why indeed. Here’s how to do it.

UseCloseButtonToStopVI

In order to catch the press of the Close button, you need to use an event structure. The event structure allows you to tie into the Panel Close? event to make it run your code.

You will find the event under <This VI>Event Source. Take note of the question mark in the event name. There is also an event called Panel Close. You need the one with the question mark. It is a filter event. Since it is a filter event, it is indicated with a red arrow.

Filter events get called before the event is processed. By wiring a TRUE to the discard, the event is killed, so the standard event handling is not processed. We have complete control over what we want to do in response to the event.

Now you have no excuse. So, please, no more “Stop” buttons.

Download Example: CloseButtonToStopVI.vi

Leave a Reply