Update Edit Box in GUI

10 ビュー (過去 30 日間)
Umar Twahir
Umar Twahir 2016 年 3 月 7 日
コメント済み: Umar Twahir 2016 年 3 月 7 日
I am making a GUI to operate a magnet field controller. I have an editable text box to enter field values, and it works when entering values from the computer keyboard. However, I also have a number pad on the GUI to update the text box that way, however, if I have to enter a value such as 200, when I enter the numbers to append on they replace the current value and only display one number at a time. Is there some way to tell the box to hold the numbers?
Thanks
Umar

採用された回答

Geoff Hayes
Geoff Hayes 2016 年 3 月 7 日
Umar - make sure that you append the new numbers to your text field rather than replacing. Assuming that you have created your GUI using GUIDE, in the callback for one of your number pad keys, do the following
function pushbutton1_Callback(hObject, eventdata, handles)
% get the current number from the editable text field
currentValue = char(get(handles.edit1,'String'));
% append the number corresponding to this callback (let's assume a '1')
newValue = [currentValue '1'];
% update the edit text field with the new value
set(handles.edit1,'String',newValue);
The above assumes that edit1 is the text field that you wish to update. Try it and see what happens!
  1 件のコメント
Umar Twahir
Umar Twahir 2016 年 3 月 7 日
Did the trick!!
Thanks

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 3 月 7 日
編集済み: Image Analyst 2016 年 3 月 7 日
If the number in the edit field is highlighted, then yes, typing anything (like a number) will replace the text that's in there. Typing a second, third, fourth number will append to the existing characters in the edit text box. That's totally normal and how all programs operate. If the edit text is not highlighted, then characters will appear one at a time at the location of the cursor as you type them. Again, totally normal. I guess I don't understand what the problem is.
If you wanted to enter 200 and not show anything until the second 0 is typed (if that's what you meant by "hold the numbers", then that's not how it works. For example how would it know that you're done and not planning on typing another number, like 2001? Plus, it's very disconcerting to the user to type and not see anything show up.
  1 件のコメント
Umar Twahir
Umar Twahir 2016 年 3 月 7 日
The issue is I would like to update the edit text box from the number pad I created in the GUI. If for instance I depress 7 then 8, 8 replaces 7 instead of appending on, regardless of the box being highlighted or not. I would like to it say 78 rather than replace 7 for 8.
Thanks Umar

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

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by