Update Edit Box in GUI

7 Ansichten (letzte 30 Tage)
Umar Twahir
Umar Twahir am 7 Mär. 2016
Kommentiert: Umar Twahir am 7 Mär. 2016
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

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 7 Mär. 2016
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!

Weitere Antworten (1)

Image Analyst
Image Analyst am 7 Mär. 2016
Bearbeitet: Image Analyst am 7 Mär. 2016
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 Kommentar
Umar Twahir
Umar Twahir am 7 Mär. 2016
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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by