Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

movegui

Move UI figure to specified location on screen

Syntax

movegui(h,position)
movegui(position)
movegui(h)
movegui

Description

movegui(h,position) moves the figure h to the specified screen location and preserves the figure's size. The position argument is either a character vector or a two-element numeric vector, as defined in the tables that follow.

movegui(position) moves the callback figure (gcbf) or the current figure (gcf) to the specified position.

movegui(h) moves the figure to the onscreen position.

movegui moves the callback figure (gcbf) or the current figure (gcf) to the onscreen position. You can specify 'movegui' as a CreateFcn callback for a figure. Doing so ensures that after you save a figure, that figure appears on screen when you reload it, regardless of its saved position. See the following example.

When it is a character vector, position is one of the following descriptors.

Position Character VectorDescription
'north'Top center edge of screen
'south'Bottom center edge of screen
'east'Right center edge of screen
'west'Left center edge of screen
'northeast'Top right corner of screen
'northwest'Top left corner of screen
'southeast'Bottom right corner of screen
'southwest'Bottom left corner
'center'Centered on screen
'onscreen'Nearest location to current location that is entirely on screen

You can also specify the position argument as a two-element numeric vector, [h,v]. Depending on sign, h specifies the figure's offset from the left or right edge of the screen, and v specifies the figure's offset from the top or bottom of the screen, in pixels. The following table summarizes the possible values.

h (for h >= 0)

Offset of left side from left edge of screen

h (for h < 0)

Offset of right side from right edge of screen

v (for v >= 0)

Offset of bottom edge from bottom of screen

v (for v < 0)

Offset of top edge from top of screen

Applying movegui to a maximized figure window moves the window towards the task bar and creates a gap on the opposite side of the screen about as wide as the task bar. The window might shrink in size by a few pixels. If you use the onscreen option with a maximized figure window, then movegui creates a gap on both the left and upper sides of the screen so that the top-left corner of the figure is visible.

GUIDE and openfig call movegui when loading figures to ensure they are visible.

Examples

Ensure that a saved UI window appears on screen when you reload it, regardless of the target computer screen size and resolution. Create a figure that is off the screen, assign movegui as its CreateFcn callback, save the figure, and then reload it.

f = figure('Position',[10000,10000,400,300]);
% The figure does not display because 
% it is created offscreen.
f.CreateFcn = @movegui;
hgsave(f,'onscreenfig');
close(f);
f2 = hgload('onscreenfig');
% The reloaded figure is now visible

Move a figure to the bottom left corner of the screen.

f = figure;
movegui(f,'southwest');

Move a figure so that it is offset 100 pixels from the bottom and left side of the screen.

f = figure;
movegui(f,[100,100]);

More About

collapse all

Pixels

Distances in pixels are independent of your system resolution on Windows® and Macintosh systems:

  • On Windows systems, a pixel is 1/96th of an inch.

  • On Macintosh systems, a pixel is 1/72nd of an inch.

On Linux® systems, the size of a pixel is determined by your system resolution.

See Also

|

Introduced before R2006a

Was this topic helpful?