フィルターのクリア

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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R14SP2

Community Treasure Hunt

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

Start Hunting!

Translated by