about uicontrols and dialog
4 views (last 30 days)
Show older comments
In my program I used a "helplg" dialog and when I close the dialog, I want the program to be terminated not same as pressing "ok" button the program be continued. In other word, when I close the helpdlg the program to be terminated not as pressing ok it follow the code instructions. How should I code this issue?
Thanks for your help
0 Comments
Answers (1)
Geoff Hayes
on 8 Nov 2017
omid - please clarify how you are using this dialog. Also, why are you using a help dialog to terminate the program?
You may be able to use the CloseRequestFcn of the dialog to capture when the user has closed the dialog (by pressing the x in the top right corner). The following code "works" on R2014a, but I would recommend finding an alternative to using a help dialog.
function sampleDialogTest
isDialogClosed = false;
h = helpdlg('Sample dialog text');
set(h,'CloseRequestFcn', @HelpDialogClosed);
uiwait(h);
if isDialogClosed
fprintf('user pressed x so ending processing...\n');
return;
end
fprintf('user pressed ok so continuing with processing...\n');
function HelpDialogClosed(hObject, eventdata)
isDialogClosed = true;
closereq;
end
end
We nest the CloseRequestFcn in the main function so that it has access to the isDialogClosed boolean. uiwait is used to halt processing until the dialog is closed at which point we check our boolean - if true, then we end processing through return. And if false, then we continue.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!