筆者走了許多彎路,終於找到這個方法,分享給大家。
'callback',@(~,~)colormapeditor(h)
如果版本老不支持“~”這種寫法,那就改成:
'callback',@(x,y)colormapeditor(h)
比如,在一個控件的回調函數中生成其他控件,並為生成的控件綁定回調函數:
1 function fun_threshold_Callback(hObject, eventdata, handles) 2 % hObject handle to fun_threshold (see GCBO) 3 % eventdata reserved - to be defined in a future version of MATLAB 4 % handles structure with handles and user data (see GUIDATA) 5 ... 6 Hnd2=uicontrol(gcf,'Style','pushbutton','String','確定','Position',[260 20 30 25]); % gcf可以省略 7 set(Hnd2,'Callback', @(x,y)fun_adaptiveThreshold(handles)); % 使用句柄調用回調函數 8 ...
下面為Hnd2要調用的調用函數:
1 function fun_adaptiveThreshold(handles) 2 % 回調函數體 3 ...
其他知識:
1.uicontrol(Hnd1); % 文本框獲得焦點
2.guidata(hObject, handles); % 更新句柄
3.在主程序面板上點擊按鈕關閉其他所有創建的窗口:
setappdata(gcf, 'IgnoreCloseAll', 1); % 防止主程序窗口被關閉
close all; % 關閉其他操作產生的窗口
....
(未完待續)