필터 지우기
필터 지우기

How can I detect a buttonup event on a uicontrol ?

조회 수: 25 (최근 30일)
MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
댓글: Mukul Rao 2017년 6월 19일
I would like to have an option so that I know when a uicontrol of style 'pushbutton' is pressed or released.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2009년 6월 27일
The ability to detect a buttonup event on a uicontrol is not available in MATLAB.
To work around this issue, you can use either of the following options:
1. Use a uicontrol of style 'togglebutton' instead of a push button and perform two different actions depending on the 'Value' property of the toggle button uicontrol. The following example shows the 'Callback' function for such a toggle button uicontrol:
function togglebutton1_Callback(hObject, eventdata, handles)
button_state = get(hObject,'Value');
if button_state == get(hObject,'Max')
% toggle button is pressed, perform action1
elseif button_state == get(hObject,'Min')
% toggle button is not pressed, perform action2
end
2. Alternatively, you can create a push button uicontrol with its 'Enable' property set to 'inactive'. Then, you can set the 'ButtonDownFcn' property on the uicontrol and the 'WindowButtonUpFcn' property on the parent figure. This can be done as shown in the example code below:
h = uicontrol('Style', 'pushbutton', 'String', 'My_pushbutton',...
'Position', [20 150 100 70], 'Enable', 'inactive','ButtonDownFcn','disp(''The button is pressed'')');
set(gcf,'WindowButtonUpFcn','disp(''The button is released'')');
Note that the second approach will not work when the figure is in a mode that uses the ‘WindowButtonUpFcn’ property, like Zoom, Pan, etc.
  댓글 수: 1
Mukul Rao
Mukul Rao 2017년 6월 19일
Hi Mandeguz, as of R2017a, there is no documented way to determine if a button-press or button-release event occurred for a push-button. The first workaround does require two clicks since it uses a toggle button. While the second workaround requires only one click, it will not work when the figure is in a mode that uses the ‘WindowButtonUpFcn’ as the post mentions.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R14SP2

Community Treasure Hunt

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

Start Hunting!

Translated by