GUI: Editting Value in a textbox

6 views (last 30 days)
Nour Mawla
Nour Mawla on 17 May 2015
Commented: Walter Roberson on 17 May 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

Answers (1)

Geoff Hayes
Geoff Hayes on 17 May 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 Comment
Walter Roberson
Walter Roberson on 17 May 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.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!