www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/xregcenterfigure.m
function xregcenterfigure(fH,size,prnt) %XREGCENTERFIGURE Center a dialog % % XREGCENTERFIGURE(FH,SIZE) places the figure FH in the center % of the screen % XREGCENTERFIGURE(FH,SIZE,PARENT) attempts to center FH inside % PARENT's position rectangle. % % Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin<2 size= get(fH,'Position'); size= size(3:4); end if nargin>2 && ~isempty(prnt) prnt= ancestor(prnt,'figure'); end scr=get(0,'ScreenSize'); if nargin<3 || isempty(prnt) || ~isgraphics(prnt) pos=[(scr(3:4)-size)./2 size]; else figpos=get(prnt,'Position'); pos=[figpos(1:2)+(figpos(3:4)-size)./2 size]; % center in parent end set(fH,'Position',pos); % ensure on screen xregmoveonscreen(fH);