我想在游標懸停在TImage組件上時才顯示一個表單,就像一個提示。我能夠使用 "OnMouseMove "事件來顯示表單,但是我不確定如何在滑鼠離開影像后隱藏表單。我怎樣才能做到這一點呢?
提前感謝
uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
在你的表單中添加一個TTimer控制元件(可能來自系統標簽控制元件),命名為Timer1。
將Timer1的Inteval屬性設定為100,這意味著它將每100毫秒檢查一次游標位置,(一秒鐘10次)。
設定 Timer1 Enabled 屬性為 True。
在 Timer1 的 OnTimer 事件中添加以下代碼:
procedure TForm1. Timer1Timer(Sender: TObject);。
var
oCursorPos: TPoint;
oImagePos: TPoint。
bInside: 布林值。
begin[/span
//Get position of Cursor in Screen Coordinates[/span]。
GetCursorPos(oCursorPos);
//將影像1的坐標從客戶端轉換為螢屏坐標。
oImagePos := Self.ClientToScreen(Point(Image1.Left, Image1.Top))。
bInside := (oCursorPos.x >= oImagePos.x) and (oCursorPos.x <= oImagePos.x Image1.Width) and
(oCursorPos.y >= oImagePos.y) and (oCursorPos.y <= oImagePos.y Image1.Height) 。
if bInside then
begin
//Cursor is over Image1 -> insert code to show the secondary form。
end
else[/span
begin
//Cursor is not over Image1 -> insert code to hide the secondary form
end。
end;
這就是全部。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/316480.html
標籤:
上一篇:制作檔案的變數操作
