如何将MATLAB应用程序设计人员创建的窗口移到屏幕中心?
目前,我正在使用app.my_fig_main.Position
更新位置。但是,此函数只能设置以下属性[left bottom width height]
。
当在不同分辨率的屏幕上运行应用程序时,我应该有某种movegui
函数,将其位置设置为center
。
不幸的是,movegui
不能在MATLAB的应用程序设计环境中工作。
在应用程序设计中有什么方法可以做到这一点吗?
发布于 2017-01-26 10:10:19
不确定我是否误解了您的问题,但是您可以使用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]);
https://stackoverflow.com/questions/41870872
复制相似问题