GUI: Editting Value in a textbox

1 次查看(过去 30 天)
Nour Mawla
Nour Mawla 2015-5-17
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

回答(1 个)

Geoff Hayes
Geoff Hayes 2015-5-17
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 个评论
Walter Roberson
Walter Roberson 2015-5-17
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by