필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Rightia Rollmann
Rightia Rollmann 2017년 2월 27일
편집: Jan 2017년 2월 27일
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');

채택된 답변

Jan
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개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by