GUI: Editting Value in a textbox

1 visualizzazione (ultimi 30 giorni)
Nour Mawla
Nour Mawla il 17 Mag 2015
Commentato: Walter Roberson il 17 Mag 2015
Good afternoon
Please I need your advice: how do I overwrite text in a textbox without deleting the old data...
i.e is the textbox already contains the letter "a" and I need to add the letter "b" , the first letter won't be deleted....but instead the textbox would contain "ab"
the textbox won't reset unless I manually cleared it...
please help

Risposte (1)

Geoff Hayes
Geoff Hayes il 17 Mag 2015
Nour - you could get the value from the edit text control, then append or concatenate the second character to it, and set the edit text control with the new string. For example,
% get the current string from the edit control
str = char(get(handles.edit1,'String'));
% update the string with the letter 'b'
str = [str 'b'];
% set the text control with the new string
set(handles.edit1,'String',str);
The above assumes that you are using GUIDE to create your GUI and that the edit text control is named (tagged) as edit1.
  1 Commento
Walter Roberson
Walter Roberson il 17 Mag 2015
Note that at least with the original Handle Graphics:
If you try to use a uicontrol KeyPressFcn callback to get access to what the user is typing as they type it, that the String property of the uicontrol will not be updated until the control is activated by pressing Enter.

Accedi per commentare.

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by