1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| function [] = clear_edit_example()
% Show how to clear and editbox string when cursor is placed over it.
handles(2) = figure('units','pixels',...
'position',[500 500 300 50],...
'menubar','none',...
'numbertitle','off',...
'name','clear_edit_example',...
'resize','off');
handles(8) = uicontrol('style','edit',...
'units','pixels',...
'position',[10 10 280 30],...
'fontsize',14,...
'string','Enter Value');
set(handles(2),'windowbuttonmotionfcn',{@fh_bmfcn,handles})
function [] = fh_bmfcn(varargin)
% This is the WindowButtonMotionFcn for the figure.
handles = varargin{3}; % Get handles structure. Use GUIDATA or whatever.
CP = get(handles(2),'currentpoint'); % Get the current point in the fig.
EDP = get(handles(8),'position'); % The position of the editbox.
if CP(1)>EDP(1)&&CP(1)<(EDP(1)+EDP(3)) % Within X range
if CP(2)>EDP(2)&&CP(2)< (EDP(2)+ EDP(4)) % Within Y range
if strmatch(get(handles(8),'string'),'Enter Value') % Starting string??
set(handles(8),'string',[])
end
end
end |
Partager