listdlg: differentiate between Cancel and X

Hello,
In listdlg, I would like to differentiate between pressing Cancel button and X.
I know both of them will result in an empty vector. But is there any work around to differentiate between these two buttons.
My plan is to have the following:
  • Press OK: call Action 1
  • Press Cancel: call Action 2
  • Press X: call Action 3
Thank you in advance!
Hasson

6 commentaires

Walter Roberson
Walter Roberson le 14 Août 2020
questdlg() or menu() might be more appropriate.
Johannes Hougaard
Johannes Hougaard le 14 Août 2020
Unfortunately it doesn't seem as if listdlg allows a specific CloseRequestFcn as that is hard-coded as 'delete(gcbf)' in the listdlg.m.
One could create a customized listdlg function...as Johannes notes, it's an m-file so can see how implemented. The hardcoded part of intererest is
fig_props = { ...
'windowstyle' 'modal' ...
'name' figname ...
'color' get(0,'DefaultUicontrolBackgroundColor') ...
'resize' 'off' ...
'numbertitle' 'off' ...
'menubar' 'none' ...
'units' 'pixels' ...
'visible' 'off' ...
'createfcn' '' ...
'position' fp ...
'closerequestfcn' 'delete(gcbf)' ...
};
liststring=cellstr(liststring);
fig = figure(fig_props{:});
...
and goes on to make the buttons, etc., ec., ...
Hassan
Hassan le 15 Août 2020
Thank you all for your helpful comments. Special thanks to dpb for his detailed explanation.
Image Analyst
Image Analyst le 15 Août 2020
Why different actions for Cancel vs. X? Is your user prompt going to explain to the user that different actions will be taken depending on which they click on? I don't think most users will expect that. I know of many uses who don't think there is, or will be, any difference between the two. Why do you want two different actions?
Hassan
Hassan le 15 Août 2020
I want to rename the Cancel button to 'More...' to be able to open a second listbox with more contents. But if the user presses the X button, then the story ends here.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange

Question posée :

le 14 Août 2020

Commenté :

le 15 Août 2020

Community Treasure Hunt

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

Start Hunting!

Translated by