How to make text in uicontrol object disappear when user starts typing?

1 次查看(过去 30 天)
I have a question about the following editable text box,
f = figure; % Make example figure
peaks; % Plot peaks data that comes preloaded with Matlab
S.ed = uicontrol('style','edit',... % Make editable text box
'units','pixels', ...
'position',[10 100 200 30],...
'fontsize',11,...
'string','Enter a Word');
How do I implement the following?
  1. When the user starts to type, the text 'Enter a Word' disappears from the text box
  2. When the user presses enter at the end of a character sequence, the entry is "done" and no more characters are accepted, similar to a carriage return?
As a user, this is how I expect text boxes to work, but I don't know how to implement it.

采纳的回答

Walter Roberson
Walter Roberson 2017-6-21
In order to do that, you have to implement a KeyPressedFcn callback for the uicontrol, and you have to manage all of the text yourself, including deletions. This gets trickier because when you are in a KeyPressedFcn callback for a text box, as you set() the String property, the display will not be updated (unless they changed that in R2014b and later), so you have to keep track of all of the text yourself.

更多回答(0 个)

类别

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