procedure TfmMain.Timer2Timer(Sender: TObject);
var
winPos: TPoint;
t: integer;
b: boolean;
begin
b:= false;
//小于3个像素
if (fmMain.Top <= 3) then
begin
b:= true;
t:= 0;
end
//当窗口的(左边距+宽度)-屏幕的宽度 大于 0 时
else if fmMain.Left + fmMain.Width - Screen.Width >= 0 then
begin
b:= true;
t:= fmMain.Top;
end
else
t:= fmMain.Top;
if b then
begin
//得到当前鼠标指针的在屏幕上的坐标
GetCursorPos(winPos);
//当鼠标指针下的窗体的Name等于frmMain.name时
if fmMain.Name = GetFormNameAt(winPos) then
{在此我们可以为frmMain取一个特别的名称,以防有别的窗体名称与它相同}
begin
//停用Timer2
fmMain.timer3.Enabled:= false;
//frmMain的Top与屏幕对齐
fmMain.Top:= t;
if t <> 0 then
fmMain.Left:= Screen.Width - fmMain.Width;
end
else begin
fmMain.Timer3.Enabled:= true;
end;
end;
end;
procedure TfmMain.Timer3Timer(Sender: TObject);
begin
// 当 top 距屏幕上侧 10 像素时,自动隐藏
if fmMain.Top <= 10 then
begin
//将frmMain向上移,在屏幕上方露出3像素
fmMain.Top:= -(fmMain.Height - 3);
if (fmMain.Left + fmMain.Width > Screen.Width) then
fmMain.Left:= Screen.Width - fmMain.Width;
end
// 当 left 距屏幕下侧 10 像素时,自动隐藏
else if fmMain.Left + fmMain.Width - Screen.Width >= -10 then
//将frmMain向右移,在屏幕右方露出4像素
fmMain.Left:= Screen.Width - 4;
end;