matlab设计GUI(例子2)

%%自制一个下拉菜单表的用户菜单,背景颜色设为蓝色
figure
h_menu=uimenu(gcf,'label','color');%%用户顶层菜单项color
h_submenul=uimenu(h_menu,'label','blue','callback','set(gcf,''color'',''blue'')');%制作下拉菜单项blue
h_submenu2=uimenu(h_menu,'label','red','callback','set(gcf,''color'',''red'')');%制作下拉菜单项red

特别提醒一下:其中“color”要用两个英文字符的单引号,不是一个双引号。不然响应不了哦

 

figure
h_menu=uimenu(gcf,'label','&option','position',3);%%用户顶层菜单项带简捷键Ccolor
h_submenul=uimenu(h_menu,'label','grid on','callback','grid on');
h_submenu2=uimenu(h_menu,'label','grid off','callback','grid on');
h_submenu3=uimenu(h_menu,'label','&color','separator','on');
h_subsub1=uimenu(h_submenu3,'label','&blue','callback','set(gcf,''color'',''blue'')');%制作带简捷键B下拉菜单项blue
%我们可以看不到到快捷键,还有所谓的简捷键是Alt+简捷字母
h_subsub2=uimenu(h_submenu3,'label','red','callback','set(gcf,''color'',''red'')','accelerator','r');%制作下拉菜单项red

%%对上一个例子的美观处理

%%
%%给菜单贴上检录符
%%每个功能区的两个菜单项是相互对立的,可见功能属性
%%绘制现场菜单
figure
t=(-3*pi:pi/50:3*pi)+eps;
y=sin(t)./t
hline=plot(t,y);
cm=uicontextmenu;
uimenu(cm,'label','red','callback','set(hline,''color'',''r''),')
uimenu(cm,'label','bule','callback','set(hline,''color'',''b''),')
uimenu(cm,'label','green','callback','set(hline,''color'',''g''),')
set(hline,'uicontextmenu',cm)%使现场菜单与sa函数相联系。
h_menu=uimenu(gcf,'label','&option','position',3);%%用户顶层菜单项带简捷键Ccolor
h_sub1=uimenu(h_menu,'label','axis on');
h_sub2=uimenu(h_menu,'label','axis off','enable','off');
h_submenu3=uimenu(h_menu,'label','grid on','separator','on','visible','on','callback',['grid on,','set(h_submenu3,''checked'',''on''),','set(h_submenu4,''checked'',''off''),']);
h_submenu4=uimenu(h_menu,'label','grid off','visible','on','callback',['grid off,','set(h_submenu4,''checked'',''on''),','set(h_submenu3,''checked'',''off''),']);
set(h_sub1,'callback',['axis on,','set(h_sub1,''enable'',''off''),','set(h_sub2,''enable'',''on''),','set(h_submenu3,''visible'',''on''),','set(h_submenu4,''visible'',''on''),']);
set(h_sub2,'callback',['axis off,','set(h_sub1,''enable'',''on''),','set(h_sub2,''enable'',''off''),','set(h_submenu3,''visible'',''off''),','set(h_submenu4,''visible'',''off''),']);
%注意对同一个名称用复制,方便且不容易错。注意在【】中‘’之前要加一个,,
%一定要主要callback中的对应的响应关系是什么。
h_submenu5=uimenu(h_menu,'label','&color','separator','on');
h_subsub1=uimenu(h_submenu5,'label','&blue','callback','set(gcf,''color'',''blue'')');%制作带简捷键B下拉菜单项blue
%我们可以看不到到快捷键,还有所谓的简捷键是Alt+简捷字母
h_subsub2=uimenu(h_submenu5,'label','red','callback','set(gcf,''color'',''red'')','accelerator','r');%制作下拉菜单项red

 

posted @ 2014-05-13 22:14  梦若然  阅读(4054)  评论(0编辑  收藏  举报