Documentation

Uicontextmenu

Create context menu

Syntax

c = uicontextmenu
c = uicontextmenu(Name,Value)
c = uicontextmenu(parent)
c = uicontextmenu(父,名称,值)

描述

example

c= uicontextmenucreates a context menu in the current figure and returns the uicontextmenu object asc. If no figure is available, then MATLAB®creates a new figure to serve as the parent.

c= uicontextmenu(Name,Value)指定one or more uicontextmenu property names and corresponding values. Use this syntax to override the default uicontextmenu property values.

example

c= uicontextmenu()creates a uicontextmenu and specifies the parent figure.

不te

单独指定父级不会使上下文菜单在UI中访问。您还必须采取以下步骤:

  • Assign the uicontextmenu to a component using theUIContextMenu财产。

  • 为Uicontextmenu创建至少一个孩子Uimenu。

看到提示部分以获取更多信息。

c= uicontextmenu(,Name,Value)指定a parent figure and one or more uicontextmenu properties.

Examples

collapse all

Specify a value for the line object’sUIContextMenu将Uicontextmenu附加到该行的属性。当用户右键单击行上的用户时,上下文菜单变得可见。例如,创建一个名为的程序文件myprogram.mthat creates a plot and attaches a uicontextmenu to the plot line:

功能myprogram f = figure('WindowStyle','normal'); ax = axes; x = 0:100; y = x.^2; plotline = plot(x,y); c = uicontextmenu;%将Uicontextmenu分配到绘图行plotline.UIContextMenu = c;% Create child menu items for the uicontextmenum1 = uimenu(c,'Label','虚线','Callback',@setlinestyle);m2 = uimenu(c,'Label','dotted','Callback',@setlinestyle);m3 = uimenu(c,'Label','solid','Callback',@setlinestyle);功能setlinestyle(来源,callbackdata)转变source.Labelcase'虚线'plotline.linestyle ='--';case'dotted'plotline.linestyle =':';case'solid'plotline.linestyle =“- - -”;endendend

The context menu appears when the user right-clicks the plot line.

从上下文菜单中选择项目更改行样式。

指定Parentproperty value of any uimenu to make it into a submenu. For instance, create a program file calledmyprogram2that creates a uicontextmenu containing one top-level menu and two submenu items:

功能myprogram2 f = figure('WindowStyle','normal'); c = uicontextmenu(f);% Assign the uicontextmenu to the figuref.UIContextMenu = c;% Create child menu of the uicontextmenutopmenu = uimenu(“父母”,C,'Label','Change Color');%创建子菜单项目m1 = uimenu(“父母”,topmenu,'Label','Red','Callback',@changecolor); m2 = uimenu(“父母”,topmenu,'Label','Green','Callback',@changecolor);功能changecolor(source,callbackdata)转变source.Labelcase'Red'f.Color = [1.0 0.80 0.80];case'Green'f.Color = [0.80 1.0 0.80];endendend

The resulting context menu appears when the user right-clicks the mouse inside the figure.

Selecting a color from the context menu changes the color of the window.

Input Arguments

collapse all

Parent figure, specified as a figure object.

Name-Value Pair Arguments

例子:'Callback',@myfunction指定myfunctionto be the function that executes when the user interacts with the context menu.

The properties listed here are only a subset, for a complete list seeContextMenu Properties.

collapse all

Context menu callback function, specified as one of these values:

  • A function handle.

  • A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.

  • A character vector containing a valid MATLAB expression. For example,'disp('Hello world')'calls thedisp功能. MATLAB evaluates this expression in the base workspace.

For more information about specifying a callback property value as a function handle, cell array, or character vector, see如何指定回调属性值.

Data Types:功能_handle|细胞|char

菜单children, returned as an empty图形Placeholderor a 1-D array of菜单objects. The children of menus are other menus that function as submenus.

您不能使用Children财产。Use this property to view the list of children or to reorder the child menu items. The order of the children in this array reflects the order of the displayed menu items.

To add a child to this list, set theParentproperty of the child component to be theUicontextmenu目的。

带有的对象HandleVisibilityproperty set to'离开'do not list in theChildren财产。

提示

满足这些要求时,在UI中可以访问上下文菜单:

  • 您可以将UicontextMenu分配给组件UIContextMenu财产。分配的组件必须是与Uicontextmenu相同的孩子。

  • You create at least one child uimenu for the uicontextmenu.

例如:

f =图;c = uicontextmenu(f);%创建一个新组件并将Uicontextmenu分配给它b = uicontrol(f,'UIContextMenu',c);%为Uicontextmenu创建子菜单m = uimenu(“父母”,C,'Label',“禁用”);

在R2006a之前引入

这个话题有帮助吗?