movegui - Move figure to specified location on screen - MATLAB (original) (raw)
Main Content
Move figure to specified location on screen
Syntax
Description
movegui([f](#mw%5F6323a2ff-0b14-4e5c-9c06-1d389bc63e38),[location](#mw%5Fddcbb331-56a4-4843-91d8-e0c5625eff8b))
moves the figure f
to the specified screen location. The figure can be one created with either the figure or uifigure function. The location can be specified as a two-element vector or as a predefined location name.
movegui([location](#mw%5Fddcbb331-56a4-4843-91d8-e0c5625eff8b))
moves the current figure (gcf
) or the callback figure (gcbf
) to the specified location. To determine the current figure or the callback figure use gcf or gcbf, respectively. Note thatgcf
and gcbf
return figures created with thefigure
function only. If one does not exist, MATLAB® creates one using figure
and moves it to the specified location.
movegui([f](#mw%5F6323a2ff-0b14-4e5c-9c06-1d389bc63e38))
moves the figure to the closest location that puts it entirely on screen.
movegui
moves the current figure or the callback figure to the closest location that puts it entirely on screen.
Examples
Move Figure with Location Vector
Create a figure and move it so that the bottom left corner is 300 pixels from the left side of the screen and 600 pixels from the bottom.
fig = uifigure; movegui(fig,[300 600]);
Move Figure with Location Name
Create a figure and move it to the bottom center of the screen.
f = figure; movegui(f,'south');
Move Current Figure
f1 = figure; f2 = figure; movegui('east');
f2
moves because it is the current figure.
Move Off-Screen Figure on Screen
Create a figure that is located far outside the upper rightmost corner of the screen. Then, move it onscreen.
f = figure('Position',[10000 10000 400 300]); movegui(f);
The figure moves to the top right corner of the screen because that is the location that is closest to its last location.
Input Arguments
f
— Figure
Figure
object
Figure, specified as a Figure
object created with either thefigure
or uifigure
function. Use this argument to specify a figure you want to move.
location
— Location
two-element numeric vector | character vector | string scalar
Location of the figure on the screen, specified as a two-element numeric vector, a character vector, or a string scalar. A numeric vector specifies _x_- and _y_-values in pixels, and a text argument specifies one of the predefined location names.
To indicate the offset of the figure from the edges of the screen in units of pixels, specify a two-element numeric vector, [x y]
. The edge of the screen that the offset is measured from depends on the sign of the vector element.
Location Vector Element | Value Range | Description |
---|---|---|
x | x >= 0 | Offset of left side from left edge of screen |
x < 0 | Offset of right side from right edge of screen | |
y | y >= 0 | Offset of bottom from bottom edge of screen |
y < 0 | Offset of top from top edge of screen |
You can also specify location
as one of these location names.
Location Name | Screen Location |
---|---|
'north' | Top center |
'south' | Bottom center |
'east' | Right center |
'west' | Left center |
'northeast' | Top right corner |
'northwest' | Top left corner |
'southeast' | Bottom right corner |
'southwest' | Bottom left corner |
'center' | Center |
'onscreen' | Location nearest to the current location that is entirely on screen |
Example: movegui(f,[150 -50])
Example: movegui('west')
More About
Pixels
Distances in pixels are independent of your system resolution on Windows® and Macintosh systems:
- On Windows systems, MATLAB defines a pixel as 1/96th of an inch.
- On Macintosh systems, MATLAB defines a pixel as 1/72nd of an inch.
On Linux® systems, your system resolution determines the size of a MATLAB pixel. For more information, see DPI-Aware Behavior in MATLAB.
Algorithms
Use with Maximized Figures
Applying movegui
to a maximized figure window moves the window towards the taskbar 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 theonscreen
option with a maximized figure window, thenmovegui
creates a gap on both the left and upper sides of the screen so that the top left corner of the figure is visible.
Version History
Introduced before R2006a