Set component position in pixels
Use this function only with GUIDE, or with apps created using
the figure
function.
setpixelposition(handle,position)
setpixelposition(handle,position,recursive)
setpixelposition(handle,position)
sets the
position, in pixels, of the component specified by
handle
. The
position
argument is a
four-element vector that specifies the location and
size of the component: [pixels from left, pixels from
bottom, pixels across, pixels high]. The first two
values in this vector are the number of pixels from the
left and bottom edge of the parent container. The last
two values specify the width and height of the
component.
setpixelposition(handle,position,recursive)
sets the position as above. If Boolean
recursive
is true, the position
is set relative to the parent figure of
handle
.
This example first creates a push button within a panel.
f = figure('Position',[300 300 300 200]); p = uipanel('Position',[.2 .2 .6 .6]); h1 = uicontrol(p,'Style','PushButton',... 'Units','normalized',... 'String','Push Button',... 'Position',[.1 .1 .5 .2]);
The example then retrieves the position of the push button and changes its position with respect to the panel.
pos1 = getpixelposition(h1); setpixelposition(h1,pos1 + [10 10 25 25]);