How to position a GUI window the same place and size where it was closed?

3 vues (au cours des 30 derniers jours)
Csaba
Csaba le 1 Déc 2017
Commenté : Greg le 14 Déc 2017
Running the GUI every user puts the GUI window to different places, as it is convenient for them (especially if they have several screens). But it opens at the same place all the time. Is it possible to position the GUI window the same place where it was closed? Also the size would be useful to keep.

Réponse acceptée

Greg
Greg le 5 Déc 2017
Modifié(e) : Greg le 10 Déc 2017
In the GUI's close or delete function:
% Documentation seems to indicate you *have* to call addpref before setpref
% the first time, but my experience says not
setpref('MyGUIName','DefaultPosition',handles.figMyGUI.Position);
EDIT: In the GUI's OutputFcn: Original text: Then in the GUI's opening function:
if ispref('MyGUIName','DefaultPosition')
guipos = getpref('MyGUIName','DefaultPosition');
handles.figMyGUI.Position = guipos;
end
These preferences should be user-specific, so shared machines shouldn't cause problems. You could add a questdlg in the close/delete function to ask if they want the position stored for next time.
  5 commentaires
Csaba
Csaba le 13 Déc 2017
Updated works perfectly. Thank you!
Greg
Greg le 14 Déc 2017
Always happy to help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by