Matlab_GUI学习笔记(三)——常用对象的属性之Figure
1. Figure
使用get函数可以方便查看各个对象的属性,一些属性可以直接通过名称来大体判断其作用,比如Figure的CloseRequestFcn
属性,即为关闭窗体时要调用的函数;CurrentCharacter
属性为当前的字符,即窗体如果能够响应键盘事件,通过这个属性来获得我们按下的是哪一个键。
>>get(figure)
Alphamap: [1×64 double]
BeingDeleted: 'off'
BusyAction: 'queue'
ButtonDownFcn: ''
Children: [0×0 GraphicsPlaceholder]
Clipping: 'on'
CloseRequestFcn: 'closereq'
Color: [0.9400 0.9400 0.9400]
Colormap: [64×3 double]
CreateFcn: ''
CurrentAxes: [0×0 GraphicsPlaceholder]
CurrentCharacter: ''
CurrentObject: [0×0 GraphicsPlaceholder]
CurrentPoint: [0 0]
DeleteFcn: ''
DockControls: 'on'
FileName: ''
GraphicsSmoothing: 'on'
HandleVisibility: 'on'
InnerPosition: [488 342 560 420]
IntegerHandle: 'on'
Interruptible: 'on'
InvertHardcopy: 'on'
KeyPressFcn: ''
KeyReleaseFcn: ''
MenuBar: 'figure'
Name: ''
NextPlot: 'add'
Number: 2
NumberTitle: 'on'
OuterPosition: [481 334.6000 574.4000 457.6000]
PaperOrientation: 'portrait'
PaperPosition: [3.0917 9.2937 14.8167 11.1125]
PaperPositionMode: 'auto'
PaperSize: [21.0000 29.7000]
PaperType: 'A4'
PaperUnits: 'centimeters'
Parent: [1×1 Root]
Pointer: 'arrow'
PointerShapeCData: [16×16 double]
PointerShapeHotSpot: [1 1]
Position: [488 342 560 420]
Renderer: 'opengl'
RendererMode: 'auto'
Resize: 'on'
Scrollable: 'off'
SelectionType: 'normal'
SizeChangedFcn: ''
Tag: ''
ToolBar: 'auto'
Type: 'figure'
UIContextMenu: [0×0 GraphicsPlaceholder]
Units: 'pixels'
UserData: []
Visible: 'on'
WindowButtonDownFcn: ''
WindowButtonMotionFcn: ''
WindowButtonUpFcn: ''
WindowKeyPressFcn: ''
WindowKeyReleaseFcn: ''
WindowScrollWheelFcn: ''
WindowState: 'normal'
WindowStyle: 'normal'
-
CloseRequestFcn
从上面get的结果可以看到,CloRequestFcn
直接指向closereq
函数,即可以通过调用这个函数来关闭窗体。下面我们在figure里面创建一个按钮来实现这一功能。hf = figure; hb = uicontrol('Style', 'pushbutton', 'Callback', 'closereq');
-
Color
窗体的颜色属性,可以控制以改变窗体的颜色,参数可以为字符或者RGB数值。set(hf, 'Color', 'w') %将颜色设置为白色
-
CurrentAxes
如果在窗体里面添加了Axes
子对象,那CurrentAxes
指向的就是当前的坐标轴对象的句柄。 -
CurrentCharacter
如果窗体能够响应键盘事件,那CurrentCharacter
指向的就是当前的键值。 -
CurrentObject
如果在CurrentAxes
中放了一个曲线,那CurrentObject
指向的就是当前的曲线对象。 -
CurrentPoint
CurrentPoint
为鼠标当前指向的位置。 -
Menubar
Menubar
为窗体的菜单栏,默认为figure
,即我们常见的默认菜单栏,如果自己创建的窗口不想要这一栏,可以通过set函数修改其属性。set(hf, 'Menubar', 'none');
-
Name&NumberTitle
Name
和NumberTitle
可以配合使用为窗体命名。如默认设置为Figure 1
。set(hf, 'NumberTitle', 'off', 'Name', 'Instance' );
-
Nextplot
Nextplot
指示下一次绘图时,是覆盖掉原来的图像重新绘制,还是在原来的基础上直接添加。 -
Position&Units
Position
和Units
一般配合使用。如果将单位设置为归一化,那么位置的参数设置在0-1之间,即取的是相对位置,则可以在不同分辨率的屏幕上有一个较为统一的布局。set(hf, 'Units', 'Normalized', 'Position', '[0.2,0.2,0.6,0.8]);
-
Resize
顾名思义Resize
指示窗体能否通过鼠标的点击拖拽再次调整大小。将属性设置为off,则不能再调整窗体大小。set(hf, 'Resize', 'off');
-
Window…(series)
以Window
开头的这几个回调函数,基本功能大同小异,下面以WindowButtonDownFcn
,WindowKeyPressFcn
结合closereq
函数为例说明如何使用:set(hf, 'WindowButtonDownFcn', 'closereq'); set(hf, 'WindowKeyPressFcn', 'closereq');
鼠标在窗体任意位置点击或者在键盘上按下任意键将会使窗体关闭。
-
WindowStyle
设置窗口模式,可以将其设置为对话框模式,即点击屏幕任意无关位置窗口不能关闭。set(hf, 'WindowStyle', 'modal');
-
Visable
窗体是否可见,用于一些调用多个子窗口的程序中,避免一次打开并显示很多窗口。pause(3) set(hf, 'Visable', 'off') pause(3) set(hf, 'Visable', 'on')