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'.
Type: double | integer
property, value
'enable'
Specifies if h is enabled. Valid values are 'on'(default) and 'off'.
Type: string
'tag'
User-defined string to tag graphical control objects.
Type: string
'userdata'
User defined numerical data.
Type: complex | mtx | scalar
'visible'
Specifies if h is visible. Valid values are 'on'(default) and 'off'.
Type: string

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});