主要内容

uifigure

创建用于设计应用程序的图形

描述

example

fig= uifigurecreates a figure for building a user interface and returns theFigureobject. This is the type of figure that App Designer uses.

example

fig= uifigure(名称,价值)指定数字properties using one or more名称,价值pair arguments.

例子

全部收缩

无花果= uifigure;

Blank UI figure window.

创建具有特定标题的UI图。

无花果= uifigure('Name','Plotted Results');

UI Figure window. The title at the top of the window is Plotted Results.

Get the location, width, and height of the figure.

p =图
ans = 680 678 560 420

Create a default UI figure.

无花果= uifigure;

Blank UI figure window.

Get the location, width, and height of the figure.

ans = 681 559 560 420

This means that the figure window is positioned 681 pixels to the right and 559 pixels above the bottom left corner of the primary display, and is 560 pixels wide and 420 pixels tall.

Halve the figure width and height by adjusting the third and fourth elements of the position vector.

图。位置(3:4)= [280 210];

Blank UI figure window. The window is half as tall as half as wide as the default window.

创建两个UI图形窗口。通过指定图1中的块交互“模态”as the窗框图2的属性值。请注意,直到图2关闭之前,您无法与图1进行交互。

fig1 = uifigure('Name','图1');fig1.Position = [500 500 370 270]; fig2 = uifigure('Name',“图2”);图2. position = [540 450 370 270];图2. windowstyle =“模态”;

Code thecloserequestfcncallback to open a modal confirmation dialog box when the user tries to close the window.

Copy and paste this code into the MATLAB®Editor, and then runcloseFig

功能closeFig fig = uifigure('Position',[100 100 425 275]); fig.CloseRequestFcn = @(src,event)my_closereq(src);功能my_closereq(fig) selection = uiconfirm(fig,“关闭图形窗口?”,。。。'Confirmation');switchselection案子'OK'delete(fig)案子'取消'返回结尾结尾结尾

单击图形关闭按钮。确认对话框打开。

Confirmation dialog box. The dialog says Close the figure window? next to a question mark icon. There are OK and Cancel buttons at the bottom.

当您悬停在按钮上时,更改显示的鼠标指针符号。

This program file, calledsetMousepointer.m, shows you how to:

  • Create a UI figure which executes custom code when the mouse is moved over a button. To do this, use the@operator to assign themouseMoved功能handle to thewindowbuttonmotionfcn图的属性。

  • 创建一个按钮并指定其坐标和标签。

  • Create a callback function calledmouseMoved使用自定义代码,您要在鼠标上移动按钮时要执行。在功能中,查询当前点属性来确定鼠标指针坐标s. Set the指针property to'手'如果the pointer coordinates are within the push button coordinates.

RunsetMousePointer。Then move the mouse over the push button to see the mouse pointer symbol change from an arrow to a hand.

功能setMousePointer fig = uifigure('Position',[500 500 375 275]); fig.WindowButtonMotionFcn = @mouseMoved; btn = uibutton(fig); btnX = 50; btnY = 50; btnWidth = 100; btnHeight = 22; btn.Position = [btnX btnY btnWidth btnHeight]; btn.Text ='Submit Changes';功能mouseMoved(src,event) mousePos = fig.CurrentPoint;如果(mousePos(1) >= btnX) && (mousePos(1) <= btnX + btnWidth)。。。&&(Mousepos(2)> = BTNY)&&(Mousepos(2)<= BTNY + BTNHEIGHT)图.pointer ='手';别的图pointer ='箭';结尾结尾结尾

带有“提交更改”的按钮的图形窗口。鼠标指针在按钮上,并处于手的形状。

输入参数

全部收缩

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, 在哪里Nameis the argument name and价值是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

Before R2021a, use commas to separate each name and value, and encloseName用引号。

例子:'Name','My App'指定我的应用as the title of the UI figure.

The properties listed here are a subset of the available properties. For the full list, seeUI Figure Properties

窗口样式,指定为以下之一:

  • 'normal'- 图形窗口独立于其他窗口,在显示图时可以访问其他窗口。

  • “模态”- 该图在所有现有的图形窗口的顶部显示,并具有正常的窗口样式,只要顶部人物的存在并保持模态,它们就无法访问。但是,将显示模式图后创建的任何新数字。

    什么时候multiple modal windows exist, the most recently created window keeps focus and stays above all other windows until it becomes invisible, or is returned to a normal window style, or is deleted. At that time, focus reverts to the window that last had focus.

  • '总在最前面'— The figure displays on top of all other windows, including modal figure windows and windows from non-MATLAB applications. The other windows are still accessible.

Note

这些是一些重要特征窗框财产和一些建议的最佳实践:

  • 什么时候you create UI windows, always specify the窗框财产。如果您还想设置调整大小or位置properties of the figure, then set the窗框属性首先。

  • 你可以更改窗框property of a figure at any time, including when the figure is visible and contains children. However on some systems, setting this property might cause the figure to flash or disappear and reappear, depending on the system's implementation of normal and modal windows. For best visual results, set the窗框property at creation time or when the figure is invisible.

UI图模式窗口样式行为

什么时候窗框被设定为“模态”, the UI figure window blocks keyboard and mouse interactions in a UI figure window that was created before it and has its可见的属性设置为'on'。For instance, in this example Figure 3 is modal with respect to Figure 2 and Figure 2 is modal with respect to Figure 1.

fig1 = uifigure('Name','图1');fig1.windowstyle =“模态”; fig2 = uifigure('Name',“图2”);图2. windowstyle =“模态”; fig3 = uifigure('Name',“图3”);fig3.WindowStyle =“模态”;
如果数字层次结构中有模态和正常图的组合,则无法保留模态层次结构。

与模态人物不同数字功能, modal figures created with theuifigure函数不会阻止对使用图形功能或MATLAB桌面创建的图形的访问。与MATLAB以外的应用程序窗口的交互也没有阻止。

打字ctrl+c当模态人物具有焦点原因时,图形可以恢复为'normal'窗框property setting. This allows the user to type at the command line.

UI数字与窗框属性设置为“模态”and the可见的属性设置为'离开'直到MATLAB使它们可见之前,请勿将其表现出来。因此,您可以隐藏一个模态窗口以供以后重复使用,而不是销毁它。

Modal figures do not display menu children, built-in menus, or toolbars. But, it is not an error to create menus in a modal figure or to change the窗框property setting to“模态”on a figure with menu children. The菜单objects exist and the figure retains them. If you reset the UI figure窗框property to'normal', the menus display.

Name of the figure, specified as a character vector or a string scalar.

例子:uifigure('Name','Results')将图的名称设置为'Results'

在应用程序设计器中,默认值Nameproperty is'MATLAB App'

UI图的位置和大小,不包括边界和标题栏,指定为表格的四元素向量[左底宽度高度]

该表描述了向量中的每个元素。

Element 描述
left Distance from the left edge of the primary display to the inner left edge of the UI figure window. This value can be negative on systems that have more than one monitor.
底部 Distance from the bottom edge of the primary display to the inner bottom edge of the UI figure window. This value can be negative on systems that have more than one monitor.
宽度 Distance between the right and left inner edges of the UI figure.
height Distance between the top and bottom inner edges of the UI figure.

限制

提示

  • 使用图形根对象设置默认值on the root level for other types of objects. For example, set the default colormap for all future figures to the夏天colormap.

    设置(groot,“ DefaultFigureColorMap”,夏天)
    To restore a property to its original MATLAB default, use the'remove'keyword.
    设置(groot,“ DefaultFigureColorMap”,'remove')
    For more information on setting default values, see默认属性值

Version History

Introduced in R2016a

展开全部