Subject Re: closing form with windows
From Leslie Shewchuk <l.shewchuk@gmail.com>
Date Sun, 24 Jan 2021 20:50:19 -0500
Newsgroups dbase.getting-started

You can use the form.CanClose() to stop it from working.  Just add a flag variable to the form when you open it.  Use the CanClose() to see if the flag is still set.  In the event where you DO want the form to close (in this example, by pressing the button) set the flag to allow the close and then call form.close()


** END HEADER -- do not remove this line
//
// Generated on 01/24/2021
//
parameter bModal
local f
f = new DontCloseForm()
if (bModal)
   f.mdi = false // ensure not MDI
   f.readModal()
else
   f.open()
endif

class DontCloseForm of FORM
   with (this)
      canClose = class::FORM_CANCLOSE
      onOpen = class::FORM_ONOPEN
      height = 7.5455
      left = 79.5714
      top = 9.8636
      width = 54.5714
      text = "Press the button"
   endwith

   this.PUSHBUTTON1 = new PUSHBUTTON(this)
   with (this.PUSHBUTTON1)
      onClick = class::PUSHBUTTON1_ONCLICK
      height = 1.5
      left = 14.0
      top = 2.5
      width = 24.0
      text = "Press here to close"
   endwith


   function PUSHBUTTON1_onClick()
                        form.closeable = true
                        form.close()
        return

   function form_canClose()
                if form.closeable = false
                        msgbox("Please don't press that button again.")
                endif
        return form.closeable

   function form_onOpen()
                        form.closeable = false
   return

endclass

The only reason the IF...Msgbox...endif is there is to show something happens.  If you remove those 3 line, it will just look like the X button is not working.

Les Shewchuk


Cornelius Wrote:

> Good morning.
> I would like to no hoe to prevent the closing of a active form with the windows red X on the top right hand side of the form.
>
> Thanks,
> Pottie
>