我能否在GUI中创建一个对象,通过将其'Position'属性设置为鼠标位置来定义它的位置(点击后拖动)?我应该使用哪个函数?
我能否在GUI中创建一个对象,通过将其'Position'属性设置为鼠标位置来定义它的位置(点击后拖动)?我应该使用哪个函数?
set(hObject,'ButtonDownFcn','selectmoveresize');
'Enable'
属性设置为'off'
或'inactive'
来禁用该对象,以便执行'ButtonDownFcn'
函数而不是'Callback'
函数。即使您没有为对象定义回调函数,这也是正确的。function GUI_example
hFigure = figure('Position',[100 100 200 200],... %# Create a figure
'MenuBar','none',...
'ToolBar','none');
hEdit = uicontrol('Style','edit',... %# Create a multi-line
'Parent',hFigure,... %# editable text box
'Position',[10 30 180 160],...
'Max',2,...
'String',{'(type here)'});
hButton = uicontrol('Style','pushbutton',... %# Create a push button
'Parent',hFigure,...
'Position',[50 5 100 20],...
'String','Turn moving on',...
'Callback',@button_callback);
function button_callback(hSource,eventData) %# Nested button callback
if strcmp(get(hSource,'String'),'Turn moving on')
set(hSource,'String','Turn moving off'); %# Change button text
set(hEdit,'Enable','inactive',... %# Disable the callback
'ButtonDownFcn','selectmoveresize',... %# Turn on moving, etc.
'Selected','on'); %# Display as selected
else
set(hSource,'String','Turn moving on'); %# Change button text
set(hEdit,'Enable','on',... %# Re-enable the callback
'ButtonDownFcn','',... %# Turn off moving, etc.
'Selected','off'); %# Display as unselected
end
end
end
注意:虽然文档将'Selected'
属性列为只读,但我可以轻松地修改它。这可能是文档中的一个错字。