about uicontrols and dialog

4 Ansichten (letzte 30 Tage)
omid
omid am 8 Nov. 2017
Kommentiert: omid am 11 Nov. 2017
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

Antworten (1)

Geoff Hayes
Geoff Hayes am 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.
  1 Kommentar
omid
omid am 11 Nov. 2017
Thanks Mr Hayes for your answer it was very helpful

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by