如何将 MATLAB 应用程序设计器创建的窗口移动到屏幕中心?
目前,我正在使用app.my_fig_main.Position
更新位置。但是,此功能只能设置以下属性[left bottom width height]
。
在具有不同分辨率的屏幕上运行应用程序时,我应该有某种movegui
功能将其位置设置为center
.
不幸的是,movegui
在 MATLAB 的应用程序设计器环境中不起作用。
有没有办法在应用程序设计器中做到这一点?
如何将 MATLAB 应用程序设计器创建的窗口移动到屏幕中心?
目前,我正在使用app.my_fig_main.Position
更新位置。但是,此功能只能设置以下属性[left bottom width height]
。
在具有不同分辨率的屏幕上运行应用程序时,我应该有某种movegui
功能将其位置设置为center
.
不幸的是,movegui
在 MATLAB 的应用程序设计器环境中不起作用。
有没有办法在应用程序设计器中做到这一点?
不确定我是否误解了您的问题,但您可以使用该figposition
功能获得当前分辨率。例如在我的笔记本电脑上:
>> figposition([0, 0, 100, 100])
ans =
0 0 1366 768
表示分辨率为 1366x768
然后,您可以set(gcf,'position', ... )
到达您想要的位置,使其处于中心位置。
您甚至可以figposition
直接在其中使用,实际上,set
直接使用百分比来显示图形的位置。
** 编辑:** 一个例子,根据要求:
% Create Figure Window (e.g. by app designer; it's still a normal figure)
MyGuiWindow = figure('name', 'My Gui Figure Window');
% Desired Window width and height
GuiWidth = 500;
GuiHeight = 500;
% Find Screen Resolution
temp = figposition([0,0,100,100]);
ScreenWidth = temp(3);
ScreenHeight = temp(4);
% Position window in center of screen, and set the desired width and height
set (MyGuiWindow, 'position', [ScreenWidth/2 - GuiWidth/2, ScreenHeight/2 - GuiHeight/2, GuiWidth, GuiHeight]);