Open App-Window on same screen as Button in another app was clicked

조회 수: 5 (최근 30일)
Nico
Nico 2023년 11월 13일
댓글: Harald 2023년 11월 16일
I am working with two monitors. When I start my app it opens on Monitor 1. Then I move it by hand to Monitor 2 an click on a App-Button to open another App-Window. This Window again opens on the Monitor 1.
Is there a possibility to move the second App-Window on Monitor 2? I would like the App to always open on the Monitor on which I am working.

채택된 답변

Harald
Harald 2023년 11월 13일
Hi Nico,
there is a default Position property that you can modify. For the purpose of this property, MATLAB treats two monitors as one wide monitor: if the first entry is greater than the horizontal number of pixels, then the figure is on monitor 2.
At least if both monitors have same resolution, the following will move a figure to the sample place on monitor 2:
s = get(0,'screensize');
w = s(3);
f = figure;
f.Position(1) = f.Position(1) + w;
I suppose you need to check the Position of your app window to know on what screen it is, and then adjust the Position of app 2 accordingly if needed.
Best wishes,
Harald
  댓글 수: 2
Nico
Nico 2023년 11월 16일
Thank you for your help! I solved it by getting the position of the left-bottom corner of the calling-app with the button. Then I moved my new object to this position and after this I centered it.
% Move window to left-bottom corner of Plotting-App to be on
% the same monitor
app.UIFigure.Position(1) = app.Plotting.callingPosition(1);
app.UIFigure.Position(2) = app.Plotting.callingPosition(2);
% Move window to the center of the monitor
movegui(app.UIFigure, 'center')
Harald
Harald 2023년 11월 16일
Nice approach, thanks for sharing! ... and good to see that movegui is smart enough to move to the center of the current screen. :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Mobile에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by