在GUI中拖放

| 是否可以在GUI中创建一个对象,该对象的位置可以通过将其'Position \'属性设置为任意光标位置来通过光标位置(单击时拖动)来定义?我应该使用什么功能?     
已邀请:
        您可以使用SELECTMOVERESIZE函数来打开和调整GUI对象的大小。然后,您只需用鼠标单击并拖动对象。就这么简单:
set(hObject,\'ButtonDownFcn\',\'selectmoveresize\');
不是那么简单的是,如果您的GUI对象是uicontrol对象,在这种情况下,您必须通过将
\'Enable\'
属性设置为
\'off\'
\'inactive\'
来禁用该对象,以便执行
\'ButtonDownFcn\'
函数而不是
\'Callback\'
函数。即使没有为对象定义回调,也是如此。 您可能还需要在GUI中添加一种方法,以打开和关闭对象的移动和调整大小,也许可以选择一个额外的按钮或菜单项。为了显示如何使用按钮来完成此操作,以下是一个简单的示例,该示例创建了一个带有可编辑文本框和打开和关闭移动和调整可编辑文本框大小功能的按钮的图形:
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
注意:尽管文档将ѭ7属性设置为只读,但我可以毫无问题地对其进行修改。它必须是文档中的错字。     
        您可以在GUI中创建不可见的轴,并在其中绘制所需的任何对象。然后,您可以使用File Exchange中的DRAGGABLE来拖动对象到处。     

要回复问题请先登录注册