www.gusucode.com > mbcguitools 工具箱 matlab 源码程序 > mbcguitools/xregmoveonscreen.m

    function xregmoveonscreen(fH)
%XREGMOVEONSCREEN Ensure figure is placed on screen
%
%  xregmoveonscreen(F) makes sure that F is fully visible on the screen.

%  Copyright 2000-2008 The MathWorks, Inc. and Ford Global Technologies, Inc.


scr = get(0,'ScreenSize');

outerpos_old = get(fH,'OuterPosition');
outerpos_new = outerpos_old;

doset = false;

% horizontal
if outerpos_new(1)<1
    outerpos_new(1) = 1;
    doset = true;
elseif (outerpos_new(1)+outerpos_new(3))>scr(3)
    outerpos_new(1) = scr(3)-outerpos_new(3);
    doset = true;
end
% vertical
if outerpos_new(2)<1
    outerpos_new(2) = 1;
    doset = true;
elseif (outerpos_new(2)+outerpos_new(4))>scr(4)
    outerpos_new(2) = scr(4)-outerpos_new(4);
    doset = true;
end

if doset
    % Playing directly with outer position can lead to shrinking windows
    % and dropping resize events, so we'll adjust the normal position
    % instead.
    pos = get(fH, 'Position');
    set(fH, 'Position', pos + (outerpos_new-outerpos_old));
end