uicontextmenu
Creates a context menu that is displayed with a right-click for a figure, uitab, or select uicontrol objects.
Syntax
h = uicontextmenu()
h = uicontextmenu(property, value, ...)
h = uicontextmenu(parent, property, value, ...)
Inputs
- parent
- Handle of a figure, uitab, or uicontrol objects of styles 'pushbutton', 'togglebutton', and 'text'.
- property, value
-
- 'createfcn'
- Function that is triggered when h is created. If value is a function handle, it must be a function that takes at least two arguments. The first argument is the handle of the uicontrol. The second argument is the event data to the uicontrol, which is ignored for createfcn. If value is a string, it must represent a function handle or a function name. If value is a cell, it must contain the function name/function handle in the first cell element and parameters to pass to callback function in the additional elements. After it is executed, createfcn cannot be interrupted.
- 'deletefcn'
- Function that is triggered when h is deleted. If value is a function handle, it must be a function that takes at least two arguments. The first argument is the handle of the uicontrol. The second argument is the event data to the uicontrol, which is ignored for createfcn. If value is a string, it must represent a function handle or a function name. If value is a cell, it must contain the function name/function handle in the first cell element and parameters to pass to callback function in the additional elements. After it is executed, createfcn cannot be interrupted.
- 'enable'
- Specifies if h is enabled. Valid values are 'on'(default) and 'off'.
- 'tag'
- User-defined string to tag graphical control objects.
- 'userdata'
- User defined numerical data.
- 'visible'
- Specifies if h is visible. Valid values are 'on'(default) and 'off'.
Outputs
- h
- Handle of the uicontextmenu created.
Examples
Create a context menu for a figure:
% Callback for menu1
function outfunc1 = func1(h,callstate)
disp('Menu item 1 callback')
end
% Callback for menu2
function outfunc2 = func2(h,callstate,argument1,argument2)
disp('Menu item 2 callback')
end
f = figure;
c = uicontextmenu(f);
% Creates individual context menu items
menu1 = uicontextmenuitem('parent', c, 'label', 'Do something', 'callback', '@func1');
menu2 = uicontextmenuitem(c, 'label', 'Do something else', 'callback', {@func2, 'foo', 1});
Create a context menu for a
button:
% Callback for menu1
function outfunc1 = func1(h,callstate)
disp('Menu 1 callback')
end
% Callback for menu2
function outfunc2 = func2(h,callstate,argument1,argument2)
disp('Menu 2 callback')
end
f = figure;
button = uicontrol('style', 'pushbutton', 'string', 'Test');
c = uicontextmenu(button);
% Creates individual context menu items
menu1 = uicontextmenuitem('parent', c, 'label', 'Do something', 'callback', '@func1');
menu2 = uicontextmenuitem(c, 'label', 'Do something else', 'callback', {@func2, 'foo', 1});