[Gambas-user] Form exit code when [X] clicked

Kad Mann nospam.nospam.nospam at ...626...
Sat Oct 17 05:24:50 CEST 2009


On Fri, 2009-10-16 at 17:44 -0700, bbb888 wrote:
> I can get an exit code from a form shown with rtn = fm.ShowDialog() correctly
> if the user uses an in-form exit such as a exit button :
> 
> 
> PUBLIC SUB btExit_Click()
> 
>     ME.Close(60)
> 
> END
> 
> 
> 
> But if the user clicks on the [X] in the titlebar all I get is 0 in rtn.  
> 
> 
> Is there a way to trap the exit in the form?

Create a new project.

Add Button1 to FMain.

Create a new form called Form1 <--- Check "Dialog box management" when
you create it. That will create the support code you need next time you
need this feature.

Replace the code in the forms as described below.

You will get 50 returned into nR if the cancel button is pressed, 150 if
OK is pressed, and 100 if the closebox is clicked.

' ***********************************************
' Paste this into FMain, replace what's there
' ***********************************************
' Gambas class file
PUBLIC SUB _new()

END

PUBLIC SUB Form_Open()

END

PUBLIC SUB Button1_Click()

  DIM nR AS Integer
  DIM f AS NEW Form1
  nR = f.Run()
  DEBUG nR
  
END



' ***********************************************
' Paste this into Form1, replace what's there
' ***********************************************
' Gambas class file

PRIVATE SomeValue AS Integer

PUBLIC SUB Run() AS Integer

  ME.ShowModal
  RETURN SomeValue

END

PUBLIC SUB btnOK_Click()

  SomeValue = 150
  ME.Close

END

PUBLIC SUB btnCancel_Click()

  SomeValue = 50
  ME.Close

END


PUBLIC SUB Form_Open()

  

END

PUBLIC SUB Form_Close()

  IF SomeValue = 0 THEN 
    SomeValue = 100
  ENDIF 

END






More information about the User mailing list