GUI figure doesn't move

7 views (last 30 days)
Andrea Le
Andrea Le on 5 Mar 2017
Commented: Andrea Le on 7 Mar 2017
Hi all,
I tried to move my GUI so part of it is in monitor 1 and the other part in monitor 2. I tried either use movegui or using groot to get all monitor position and set the figure handle to the set position but the GUI . My first monitor has [3200x1800] pixels and the second monitor is [1024x768]. Any suggestion please?
r = groot;
pos = r.MonitorPositions;
posShift = [pos(2,1)-500,pos(2,2)];
set(handles.figure1,'position',pos(1,1:2)+posShift ,pos(1.3:4)]);
  2 Comments
Sam McDonald
Sam McDonald on 7 Mar 2017
The last line of code seems to have a few typos. I assume this is what you wanted:
set(handles.figure1,'Position',[pos(1,1:2)+posShift, pos(1,3:4)]);
Jan
Jan on 7 Mar 2017
The shown code should move the GUI. The only possible problem could be, that it does not move it to the desired position. Therefore Sam's idea could be the point: Perhaps the figure is not moved, because the line contains typos and Matlab stops with an error?

Sign in to comment.

Accepted Answer

Jan
Jan on 7 Mar 2017
There is a limitation with setting the size of a Matlab figure e.g. when the limits exceed the monitor size:
siz = get(groot, 'ScreenSize'); % e.g. [1 1 1920 1200]
FigH = figure('OuterPosition', siz);
drawnow;
get(FigH, 'OuterPosition');
Under Windows you can use https://www.mathworks.com/matlabcentral/fileexchange/31437-windowapi to set the window where ever you want, even in fullscreen (on top on the taskbar) or beyound several screens.

More Answers (1)

Sam McDonald
Sam McDonald on 7 Mar 2017
Edited: Sam McDonald on 7 Mar 2017
Assuming you are using GUIDE to build your GUI, this may simply be a limitation of GUIDE or using MATLAB on multiple monitors. Although there are settings available to access the screen sizes and position the GUI across multiple monitors, the resulting GUI position may not be what you asked for. This is especially the case when positioning GUIs that are larger than the resolution of one of your monitors. However, there are still a couple steps you could try:
1. Verify that you are working with pixel units by executing the following code:
set(handles.figure1, 'Units', 'Pixels');
2. Change to "Proportional" resize behavior (Tools -> GUI Options -> Resize Behavior, and change that to "Proportional").
3. Use App Designer, which has been introduced as a replacement to GUIDE since the R2016b release. It may have the functionality you are looking for.
Technically, MATLAB is not fully supported on ALL dual-monitor setups as it is not practical to qualify every possible setup.
  1 Comment
Andrea Le
Andrea Le on 7 Mar 2017
Thank you Sam. I didn't know about the App Designer. I'll check it out

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!