about uicontrols and dialog

4 ビュー (過去 30 日間)
omid
omid 2017 年 11 月 8 日
コメント済み: omid 2017 年 11 月 11 日
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

回答 (1 件)

Geoff Hayes
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.
  1 件のコメント
omid
omid 2017 年 11 月 11 日
Thanks Mr Hayes for your answer it was very helpful

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by