【问题标题】:How to move a window created using MATLAB app designer to the center of screen?如何将使用 MATLAB 应用程序设计器创建的窗口移动到屏幕中心?
【发布时间】:2017-06-11 18:30:55
【问题描述】:

如何将 MATLAB 应用程序设计器创建的窗口移动到屏幕中心?

目前,我正在使用app.my_fig_main.Position 来更新位置。但是这个函数只能设置以下属性[left bottom width height]

当在不同分辨率的屏幕上运行应用程序时,我应该有某种movegui 函数将其位置设置为center

很遗憾,movegui 在 MATLAB 的应用程序设计器环境中不起作用。

有没有办法在应用程序设计器中做到这一点?

【问题讨论】:

    标签: matlab user-interface matlab-guide matlab-gui


    【解决方案1】:

    不确定我是否误解了您的问题,但您可以使用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]);
    

    【讨论】:

    • 编译我的应用程序后,它会返回这个错误:undefined function 'gifposition' for input arguments of type 'double''在MATLAB环境中运行我的应用程序没有任何问题。
    • 你有一个错字。 figposition,而不是 gifposition。
    猜你喜欢
    • 2017-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-26
    • 2017-09-17
    • 1970-01-01
    • 2018-05-18
    • 1970-01-01
    相关资源
    最近更新 更多