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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM