Borrar filtros
Borrar filtros

How to Execute Something When a Graphics Object is Left-Clicked?

1 visualización (últimos 30 días)
Rightia Rollmann
Rightia Rollmann el 27 de Feb. de 2017
Editada: Jan el 27 de Feb. de 2017
I want the red rectangle to turn green when I only “left-click” (not right-click or middle click) on it. What is the easiest solution?
hax = axes('XLim', [0 4], 'YLim', [0 4]);
r = rectangle('Position', [1 1 1 1], 'FaceColor', 'r');

Respuesta aceptada

Jan
Jan el 27 de Feb. de 2017
Editada: Jan el 27 de Feb. de 2017
function test
FigH = figure;
hax = axes('XLim', [0 4], 'YLim', [0 4]);
r = rectangle('Position', [1 1 1 1], 'FaceColor', 'r', ...
'ButtonDownFcn', {@RectClickCB, FigH});
function RectClickCB(RectH, EventData, FigH)
switch get(FigH, 'SelectionType')
case 'normal' % Left click
set(RectH, 'FaceColor', 'g');
case 'alt' % Right click
case 'extend' % Middle click
otherwise
...
end

Más respuestas (0)

Categorías

Más información sobre Graphics Object Programming en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by