How do I create a button that doesn't close a dialog?
Moderators: Dorian (MJT support), JRL
How do I create a button that doesn't close a dialog?
I want a button in a dialog that performs a subroutine and nothing else. I want the dialog to stay open. I have added an AddDialogHandler statement that performs the subroutine, but the dialog closes. How do I stop it?
Last edited by bossydog9 on Sun Feb 02, 2020 5:19 pm, edited 1 time in total.
Re: How do I create a button that doesn't close a dialog
Edit: Fixed the Dialog caption so the script will run.
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Caption = 'Button Won''t Close'
ClientHeight = 269
ClientWidth = 429
object MSButton1: tMSButton
Left = 170
Top = 170
Width = 75
Height = 25
Caption = 'Press Me'
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSButton1,OnClick,DoIt
AddDialogHandler>Dialog1,,OnClose,Quit
Show>Dialog1,
SRT>DoIt
MDL>Would have been nice to have seen your script but did you not add a comma to the Show>Dialog line
END>DoIt
SRT>Quit
Exit
END>Quit
Re: How do I create a button that doesn't close a dialog?
Your script doesn't load because of the single apostrophe in the caption property (Won't should have 2 apostrophes - Won''t).
It turns out that in order for a button to perform a subroutine and not close the form, its ModalResult must be zero.
It turns out that in order for a button to perform a subroutine and not close the form, its ModalResult must be zero.
Note that if a button's ModalResult value is zero (the default) it will not close the dialog. To respond to button clicks for buttons that should not close the dialog, leave ModalResult for those buttons to zero and create an event handler with the AddDialogHandler command.
Re: How do I create a button that doesn't close a dialog?
Fixed the dialog. Sorry for any confusion.
You are correct that the modalresult property must be set to zero. Its been so long since I've used the pre-version 12 dialog format that I'd forgotten about that. It is important to note that you will never see the modal result until the dialog closes. If you are using dialog event handlers, I can only think of one reason to ever set a button's modalresult property (the default is zero), that would be to have the dialog close when the button is picked.
If you do want to use modalresult and have the dialog stay open, just add another Show>Dialog at an appropriate location in the script. Or maybe add a loop.
You are correct that the modalresult property must be set to zero. Its been so long since I've used the pre-version 12 dialog format that I'd forgotten about that. It is important to note that you will never see the modal result until the dialog closes. If you are using dialog event handlers, I can only think of one reason to ever set a button's modalresult property (the default is zero), that would be to have the dialog close when the button is picked.
If you do want to use modalresult and have the dialog stay open, just add another Show>Dialog at an appropriate location in the script. Or maybe add a loop.
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Caption = 'Button Won''t Close'
ClientHeight = 269
ClientWidth = 429
object MSButton1: tMSButton
Left = 170
Top = 170
Width = 75
Height = 25
Caption = 'Press Me'
ModalResult = 99
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSButton1,OnClick,DoIt
//AddDialogHandler>Dialog1,,OnClose,Quit
Let>Count=0
Label>RestartDialog1
If>Buttonresult={"Buttonresult"}
Show>Dialog1,Buttonresult
Else
MDL>Buttonresult = %Buttonresult%%crlf%Count = %Count%
If>Buttonresult=2
Exit
EndIf
Show>Dialog1,Buttonresult
EndIf
Goto>RestartDialog1
SRT>DoIt
//Do Button Stuff
Add>Count,1
END>DoIt
/*
SRT>Quit
Exit
END>Quit
*/
Re: How do I create a button that doesn't close a dialog?
If you have a button in your dialog then just set its ModalResult = 0.