uifigure
创建用于设计应用程序的图形
Syntax
描述
例子
Create Default UI Figure
无花果= uifigure;
Set and Access Properties
创建具有特定标题的UI图。
无花果= uifigure('Name','Plotted Results');
Get the location, width, and height of the figure.
p =图
ans = 680 678 560 420
更改数字大小
Create a default UI figure.
无花果= uifigure;
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];
创建模态UI图
创建两个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 CloseRequestFcn to Confirm Closing UI Figure
Code thecloserequestfcn
callback 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)案子'取消'返回结尾结尾结尾
单击图形关闭按钮。确认对话框打开。
Change Mouse Pointer Symbol
当您悬停在按钮上时,更改显示的鼠标指针符号。
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 called
mouseMoved
使用自定义代码,您要在鼠标上移动按钮时要执行。在功能中,查询当前点
属性来确定鼠标指针坐标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
, 在哪里Name
is 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。
窗框
—Window style
'normal'
(default) |“模态”
|'总在最前面'
窗口样式,指定为以下之一:
'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
—Name
''
(default) |角色向量|string scalar
Name of the figure, specified as a character vector or a string scalar.
例子:uifigure('Name','Results')
将图的名称设置为'Results'
。
在应用程序设计器中,默认值Name
property is'MATLAB App'
。
位置
—UI图的位置和大小,不包括边界和标题栏
[左底宽度高度]
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. |
限制
Currently, you cannot pass a
Figure
用uifigure
功能to the打印
功能。If you attempt to do so, MATLAB throws an error. For more information, see在应用程序设计师中显示图形。
提示
使用图形根对象设置默认值on the root level for other types of objects. For example, set the default colormap for all future figures to the
夏天
colormap.设置(groot,“ DefaultFigureColorMap”,夏天)
'remove'
keyword.设置(groot,“ DefaultFigureColorMap”,'remove')
Version History
Introduced in R2016aR2021a:创建留在前景中的UI数字
要将特定的UI图形窗口放在其他窗口的前面,请设置窗框
property to'总在最前面'
。与模态图不同,带有此属性设置的UI图形窗口不限制键盘和鼠标交互。
有关更多信息,请参阅UI Figure Properties。
matlab命令
您单击了与此MATLAB命令相对应的链接:
通过在MATLAB命令窗口中输入该命令。Web浏览器不支持MATLAB命令。万博1manbetx
选择一个网站
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
您还可以从以下列表中选择一个网站:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
美洲
- América Latina(Español)
- 加拿大(英语)
- 美国(英语)