How to Execute Something When a Graphics Object is Left-Clicked?
1 次查看(过去 30 天)
显示 更早的评论
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');
0 个评论
采纳的回答
Jan
2017-2-27
编辑:Jan
2017-2-27
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
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Graphics Object Programming 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!