procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br> Cursor: TPoint ;<br> WDZzone: TRect ;<br>begin<br> GetCursorPos(Cursor) ; //获得鼠标的当前位置<br> GetWindowRect(Handle,WDZzone) ; //获得窗口的区域<br> if self.Top <3 then<br> begin<br> if not PtInRect(WDZzone,Cursor) then //判断鼠标是否在窗口里<br> self.Top := 0-self.Height+1 //窗体在屏幕上方<br> else<br> self.Top := 0 ;<br> end<br> else if self.Left > screen.Width-self.Width-5 then<br> begin<br> if not PtInRect(WDZzone,Cursor) then //窗体在屏幕右方<br> self.Left := screen.Width -1<br> else<br> self.Left := screen.Width-self.Width<br> end<br> else if self.Left <3 then<br> begin<br> if not PtInRect(WDZzone,Cursor) then //窗体在屏幕左方<br> self.Left := 0-self.Width +1 <br> else<br> self.Left := 0 ;<br> end <br>end;<br>再把窗体的FormStyle属性设为fsStayOnTop效果会更好