You can use the SELECTMOVERESIZE function to enable moving and resizing for your GUI object. Then you can just click and drag the object. It is so simple:
set(hObject,'ButtonDownFcn','selectmoveresize');
Which is not so simple if your GUI object is a uicontrol object , in which case you will have to disable the object by setting the 'Enable' property to 'off' or 'inactive' to 'ButtonDownFcn' instead of the 'Callback' function. This is true even if you did not define a callback for the object.
You will also probably need to add tools for your GUI to enable or disable moving and resizing the object, perhaps an additional button or menu item that you can select. To show how you can do this with a button, here is a simple example that creates a shape with an editable text field and a button that turns on and off the ability to move and resize the editable text field:
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
Note: although the documentation says the 'Selected' property is read-only, I was able to change this without a problem. This should be a typo in the documentation.