Matlab_GUI的菜单和工具栏常用操作(2)
时间:2025-07-10
时间:2025-07-10
toolbar'); if isempty(hToolbar), return, end 4% get all children hChildren = allchild(hToolbar); if isempty(hChildren), return,end
hTags = get(hChildren, ‘Tag’);
hTags保存了工具栏所有按钮的tag值:
6. 获取设置figure工具栏按钮的callback函数 %reset callback function for "Zoom in" hZoomIn = findobj(hChildren,'Tag','Exploration.ZoomIn'); set(hZoomIn,'ClickedCallback',@tbZoomIn_Callback);
function tbZoomIn_Callback(hObject, eventdata) % hObject handle to tbZoomIn (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB
7. 删除figure工具栏按钮 % set figure toolbar first set(hObject,'Toolbar','figure'); % get toolbar handle tbh = findall(hObject,'Type','uitoolbar'); if isempty(tbh), return, end % toolbar buttons collection hChildren = allchild(tbh); if isempty(hChildren), return, end % delete data cursor button hDeleted = findobj(hChildren,'Tag','Exploration.DataCursor'); delete(hDeleted); 5
8. 设置figure工具栏按钮的状态 % get toolbar handle hToolbar = findall(gcf,'Type','uitoolbar'); if isempty(hToolbar), return, end % get all children hChildren = allchild(hToolbar); if isempty(hChildren), return,end hTags = get(hChildren, 'Tag'); % find "Zoom In" button hb = findobj(hChildren,'Tag','Exploration.ZoomIn'); if isempty(hb),return, end % set state if strcmp(get(hObject, 'Checked'),
'on') set(hObject, 'Checked', 'off'); set(hb,'State', 'off'); else set(hObject, 'Checked', 'on'); set(hb,'State', 'on'); end
上一篇:有机合成材料