没人理!自己 顶一下!
这个程序包含:pushbuton,frame,text,
实现多个radio button的单选,
鼠标右键驱动(uicontextmenu)和菜单(uimenu)的实现.
function myguide2-2
% matlab 控件技术实现
% copyright
% cheng wf 2007 8 20 20:06
%
clear all
clc
figwin=figure('position',[100 100 600 300],...
'name','Uicontrol:plot sin(x)',...
'menubar','none',...
'NumberTitle','off');
axeshandle=axes('position',[0.4 0.1 0.5 0.7],'box','on');
% create custom menu:zoom
itemzoom=uimenu(figwin,'label','&zoom');
itemzoomon=uimenu(itemzoom,'label','On');
itemzoomoff=uimenu(itemzoom,'label','Off');
set(itemzoomon,...
'callback',['zoom on']);
set(itemzoomoff,...
'callback',['zoom out']);
% create a frame
framebox=uicontrol(figwin,...
'style','frame',...
'position',[30 30 140 265]);
% create three radio buttons.
RadioNum=3;
for i=1:RadioNum
Radio_h(i)=0;
end
Radio_h(1)=uicontrol(figwin,...
'style','radio',...
'position',[50 250 100 30],...
'String','Draw in Red',...
'max',2,...
'CallBack',...
[ 'if get(gcbo,''value'')==1;',...
'set(Radio_h(Radio_h~=gcbo),''value'',0);',...
'end;',...
'ColorStr=''r'';'...
'set(get(gca,''children''),''Color'',''red'')']);
Radio_h(2)=uicontrol(figwin,'style','radio',...
'position',[50 210 100 30],...
'string','Draw in Green',...
'max',2,...
'CallBack',...
['if get(gcbo,''value'')==1;',...
'set(Radio_h(Radio_h~=gcbo),''value'',0);',...
'end;',...
'ColorStr=''g'';'...
'set(get(gca,''children''),''Color'',''green'')']);
Radio_h(3)=uicontrol(figwin,...
'style','radio',...
'position',[50 170 100 30],...
'string','Draw in Blue',...
'max',2,...
'CallBack',...
['if get(gcbo,''value'')==1;',...
'set(Radio_h(Radio_h~=gcbo),''value'',0);',...
'end;',...
'ColorStr=''b'';'...
'set(get(gca,''children''),''Color'',''blue'')']);
% create a text
h1=uicontrol(figwin,...
'style','text',...
'string','函 数 曲 线 图:',...
'position',[300 245 150 25],...
'fontsize',16,...
'backgroundcolor',get(gcf,'color'));
% create three buttons
push1=uicontrol(figwin,...
'style','push',...
'position',[50 120 100 30],...
'string','Plot sin(x)',...
'callback',...
['x=0:pi/20:2*pi;'...
'Funhandle=plot(x,sin(x),ColorStr);'...
'axis([0 2*pi -1 1]);'])
push2=uicontrol(figwin,...
'style','push',...
'position',[50 80 100 30],...
'string','Cla',...
'callback',['cla']);
push3=uicontrol(figwin,...
'style','pushbutton',...
'position',[50 40 100 30],...
'string','Exit',...
'callback',['close']);
% 建立鼠标右键所驱动的选项,句柄值返回rightmouse_point
rightmouse_point=uicontextmenu;
uimenu(rightmouse_point,'label','Width_2','callback','set(Funhandle,''linewidth'',2)');
uimenu(rightmouse_point,'label','Width_4','callback','set(Funhandle,''linewidth'',4)');
uimenu(rightmouse_point,'label','Width_6','callback','set(Funhandle,''linewidth'',6)');
uimenu(rightmouse_point,'label','Original','callback','set(Funhandle,''linewidth'',1)');
set(gca,'uicontextmenu',rightmouse_point) |