フィルターのクリア

Problem with Toggling Invisibility of Edit Text Box

2 ビュー (過去 30 日間)
Caleb Helmen
Caleb Helmen 2020 年 1 月 23 日
コメント済み: Caleb Helmen 2020 年 1 月 28 日
I've been trying to toggle the invisibility of a text box and its labels using the state buttons in Matlab, but can't figure out why it doesn't work.
There aren't any error messages popping up, just that when I press the state button in my GUI, nothing happens.
function StateButton_Pushed(app, eventdata)
button_state = get(app.StateButton, 'Value');
if button_state == get(app.StateButton, 'Max')
set(app.StateEditFieldLabel, 'Visible', 'on');
set(app.StateEditField, 'Visible','on');
elseif button_state == get(app.StateButton, 'Min')
set(app.StateEditFieldLabel, 'Visible', 'off');
set(app.StateEditField, 'Visible','off');
end
end
Also I have the StateEditField and StateEditFieldLabel both preset to be invisible in the constructor.
What is the problem here?
  4 件のコメント
Caleb Helmen
Caleb Helmen 2020 年 1 月 24 日
Thank you! I'll try that.
StateButton is a toggle button. Also what exactly does drawnow() do?
Geoff Hayes
Geoff Hayes 2020 年 1 月 24 日
編集済み: Geoff Hayes 2020 年 1 月 24 日
drawnow updates the figure and processes the callbacks. Is there something in the eventdata that might help you determine the state of the toggle button?

サインインしてコメントする。

採用された回答

Allen
Allen 2020 年 1 月 24 日
With App Designer you need to look at the Object's value property as you are doing. However, it will return a logical value. If it is depressed it will return 1 (true), else it will return 0 (false).
function StateButton_Pushed(app, eventdata)
value = app.StateButton.Value;
if value % I am considering this the pressed state
set(app.StateEditFieldLabel, 'Visible', 'on');
set(app.StateEditField, 'Visible','on');
elseif ~value % I am considering this the normal state
set(app.StateEditFieldLabel, 'Visible', 'off');
set(app.StateEditField, 'Visible','off');
end
end
  1 件のコメント
Caleb Helmen
Caleb Helmen 2020 年 1 月 28 日
Thank you, this helped. I changed the code to receive logical values for the .Value statements and it seemed to make it work.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by