Placing 2 related GUI's

1 回表示 (過去 30 日間)
Sebastian Ciuban
Sebastian Ciuban 2015 年 3 月 11 日
コメント済み: Adam 2015 年 3 月 11 日
Hello there,
Is there any way to position a GUI having as reference another GUI in Matlab?.
For example If I'm making a main GUI and after I press the pushbutton the 2nd GUI should open in a specific position having as reference the main GUI, not in a random place on the screen. Is this possible?.
I have attached an example.

採用された回答

Adam
Adam 2015 年 3 月 11 日
編集済み: Adam 2015 年 3 月 11 日
Launch your second gui as:
hFig2 = SecondGUI;
set( hFig2, 'Position', [x y width height] );
where [x y width height] are whatever you want them to be taken from the GUI that is launching the second GUI.
You can get the current GUI's position using it's tag as e.g.
get( hFig1, 'Position' )
If you prefer you can pass position as an argument when you launch your second GUI:
hFig2 = SecondGUI( 'Position', [x y width height] );
  2 件のコメント
Sebastian Ciuban
Sebastian Ciuban 2015 年 3 月 11 日
Your method works also. But I'm asking you the same question as I did with Image Analyst: If I move my main GUI is it possible for the 2nd GUI to remain in the same position according to the main one?
Adam
Adam 2015 年 3 月 11 日
It is probably possible...
You can add a 'PostSet' listener to your main figure's 'Position' property when you spawn the 2nd GUI. Pass the handle of the 2nd GUI into the callback. Then in the callback you can set the size of teh 2nd figure relative to that of the first. Something a bit like this, but I haven't ever tested doing this - it is just based on similar 'PostSet' listeners and callbacks I have done:
hFig2 = SecondGUI;
handles.posListener = addlistener( handles.figure1, 'Position', 'PostSet', @(src,evt) doPositionChangedCallback( handles.figure1, hFig2 ) );
function doPositionChangedCallback( hFig1, hFig2 ) )
% Code here to manipulate hFig2 'Position' based on hFig1 'Position'

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 3 月 11 日
Try to adapt this:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
The 4 numbers are x, y, width, and height, and are normalized 0 to 1 with 1 being full screen. Adjust them for each figure. Be sure to pass in the handle for each figure instead of gcf like I did.
  1 件のコメント
Sebastian Ciuban
Sebastian Ciuban 2015 年 3 月 11 日
It works. But what if I move the main GUI? It is possible for the 2nd GUI to "follow" it and remain in the same position according to the main one?

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

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by