about uicontrols and dialog
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Geoff Hayes
2017-11-8
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!