uicontextmenu
Creates a context menu which is displayed with a right-mouse 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
-
- '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
% 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});
% 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});