Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the <a href="http://www.mathworks.com/help/techdoc/ref/selectmoveresize.html" rel="nofollow">SELECTMOVERESIZE</a> function to turn on moving and resizing for your GUI object. Then you can just click and drag the object with the mouse. It's as simple as this:</p> <pre><code>set(hObject,'ButtonDownFcn','selectmoveresize'); </code></pre> <p>What's not so simple is if your GUI object is a <a href="http://www.mathworks.com/help/techdoc/ref/uicontrol.html" rel="nofollow">uicontrol object</a>, in which case you will have to disable the object by setting the <a href="http://www.mathworks.com/help/techdoc/ref/uicontrol_props.html#Enable" rel="nofollow"><code>'Enable'</code> property</a> to <code>'off'</code> or <code>'inactive'</code> in order to have the <a href="http://www.mathworks.com/help/techdoc/ref/uicontrol_props.html#ButtonDownFcn" rel="nofollow"><code>'ButtonDownFcn'</code></a> function execute instead of the <a href="http://www.mathworks.com/help/techdoc/ref/uicontrol_props.html#Callback" rel="nofollow"><code>'Callback'</code></a> function. This is true even if you haven't defined a callback for the object.</p> <p>You will also probably need to add a means to your GUI to turn the moving and resizing of the object on and off, perhaps an extra button or a menu item you can select. To show how you could do this with a push button, here's a simple example that creates a figure with an editable text box and a push button that turns on and off the ability to move and resize the editable text box:</p> <pre><code>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 </code></pre> <p><strong>Note:</strong> although the documentation lists the <a href="http://www.mathworks.com/help/techdoc/ref/uicontrol_props.html#Selected" rel="nofollow"><code>'Selected'</code> property</a> as read-only, I was able to modify it without a problem. It must be a typo in the documentation.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload