Dealing with the 'x' in a Dialog Box
Moderators: Dorian (MJT support), JRL
Dealing with the 'x' in a Dialog Box
Good day all,
I'm trying to create a pretty sophisticated dialog box in macro scheduler, and I'm stuck when it comes to someone clicking the 'x' in the top right hand corner. I'd like to capture that click and present an Ask box confirming closing the box.
How can that be done?
Thanks!
Frank
I'm trying to create a pretty sophisticated dialog box in macro scheduler, and I'm stuck when it comes to someone clicking the 'x' in the top right hand corner. I'd like to capture that click and present an Ask box confirming closing the box.
How can that be done?
Thanks!
Frank
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Dealing with the 'x' in a Dialog Box
Yes. Set a handler for the OnClose or OnCloseQuery event.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: Dealing with the 'x' in a Dialog Box
Thanks Marcus, but do you have an example of this? I'm still finding that the window is closing on me and I cannot stop this.
I'd like to mimic the functionality of the 'cancel' button where I have a dialog hander such as:
Thanks!
Frank
I'd like to mimic the functionality of the 'cancel' button where I have a dialog hander such as:
Code: Select all
AddDialogHandler>Dialog1,MSButton2,OnClick,VerifyCancel
SRT>VerifyCancel
Ask>Are You Sure You Wish To Cancel?,varVerifyCancel
if>varVerifyCancel=YES
CloseDialog>Dialog1
Exit>0
Endif>
END>VerifyCancel
Frank
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Dealing with the 'x' in a Dialog Box
This works for me:
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Left = 454
Top = 162
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 212
ClientWidth = 476
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object MSButton1: tMSButton
Left = 133
Top = 137
Width = 75
Height = 25
Caption = 'Cancel'
TabOrder = 8
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSButton1,OnClick,doCancel
Show>Dialog1,r
SRT>doCancel
Ask>Are you sure?,yesNo
If>YesNo=YES
CloseDialog>Dialog1
Endif
END>doCancel
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: Dealing with the 'x' in a Dialog Box
Good day Marcus,
I tried your program and yes, the way you have the cancel button working - I want the same functionality with the 'x' at the top right hand side of the window. I want the dialog to stay open and confirm closing it if someone clicks the 'x' as well.
Thanks!
Frank
I tried your program and yes, the way you have the cancel button working - I want the same functionality with the 'x' at the top right hand side of the window. I want the dialog to stay open and confirm closing it if someone clicks the 'x' as well.
Thanks!
Frank
Re: Dealing with the 'x' in a Dialog Box
Its a little more complicated to deal with the close dialog "X" than to have a separate button. But I understand why you'd want to have control. I'm notorious for picking the "X" when I really didn't want to close the window.
I don't know of any way to do this using a modal dialog. Here is Marcus' example converted to a non-modal dialog and with a close dialog handler, flag variables and labels added to control what happens when the "X" is selected. You will notice that we can't stop the dialog from closing, what happens is we let it close then reopen it if the user selects "No" when asked, "Are you sure?".
I don't know of any way to do this using a modal dialog. Here is Marcus' example converted to a non-modal dialog and with a close dialog handler, flag variables and labels added to control what happens when the "X" is selected. You will notice that we can't stop the dialog from closing, what happens is we let it close then reopen it if the user selects "No" when asked, "Are you sure?".
Code: Select all
Dialog>Dialog1
object Dialog1: TForm
Left = 454
Top = 162
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'CustomDialog'
ClientHeight = 212
ClientWidth = 476
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object MSButton1: tMSButton
Left = 133
Top = 137
Width = 75
Height = 25
Caption = 'Cancel'
TabOrder = 8
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSButton1,OnClick,doCancel
AddDialogHandler>Dialog1,,OnClose,doCancel
Label>DisplayDialog
Let>ReDisplayDialogFlag=0
Show>Dialog1
Label>Loop
Wait>0.01
If>ReDisplayDialogFlag=1
Goto>DisplayDialog
EndIf
Goto>Loop
SRT>doCancel
If>ReDisplayDialogFlag=0
Ask>Are you sure?,yesNo
If>YesNo=YES
Let>ReDisplayDialogFlag=2
CloseDialog>Dialog1
//You may want to Exit> here
//Exit>0
Else
Let>ReDisplayDialogFlag=1
Endif
EndIf
END>doCancel
Re: Dealing with the 'x' in a Dialog Box
Thanks JRL,
I kind of thought that may be the way, but I wasn't sure how to implement or if the fields would retain their values. But all looks good!
Thanks a bunch.
Frank
I kind of thought that may be the way, but I wasn't sure how to implement or if the fields would retain their values. But all looks good!
Thanks a bunch.
Frank
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Re: Dealing with the 'x' in a Dialog Box
Another option for you in case you hadn't thought of it... Personally, I usually remove those "windows" options completely so folks have to use my controls.
etc...
Code: Select all
Dialog>UADialaog1
object UADialaog1: TForm
Left = 845
Top = 507
HelpContext = 5000
BorderIcons = []
BorderStyle = bsSingle
Caption = 'UAD Mover 4'
ClientHeight = 288
ClientWidth = 345
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Menu = MainMenu
OldCreateOrder = True
Position = poScreenCenter
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
Phil Pendlebury - Linktree
Re: Dealing with the 'x' in a Dialog Box
I like Phil Pendlebury post idea of removing the X in the title bar.
I'm using MS 14
* Go to the dialog editor
* Click the background or title bar to give the whole form focus
* Look at the properties window should say something like "Properties for: dialog"
* scroll down in properties to BORDER ICONS and deselect biSystemMenu from the dropdown menu.
I'm using MS 14
* Go to the dialog editor
* Click the background or title bar to give the whole form focus
* Look at the properties window should say something like "Properties for: dialog"
* scroll down in properties to BORDER ICONS and deselect biSystemMenu from the dropdown menu.
- Phil Pendlebury
- Automation Wizard
- Posts: 543
- Joined: Tue Jan 16, 2007 9:00 am
- Contact:
Re: Dealing with the 'x' in a Dialog Box
Or use what I posted above:
Code: Select all
BorderIcons = []
BorderStyle = bsSingle
Phil Pendlebury - Linktree