这是针对TScreen.Cursor
的{{3}}中所解释的故意行为:
...当Cursor为crDefault时,各个对象确定
光标图像。分配其他任何值都会设置鼠标光标图像
属于该应用程序的所有窗口。全局鼠标光标
图像保持有效,直到更改屏幕的Cursor属性
回到crDefault。 ..
窗口控件在TWinControl.WMSetCursor
过程中处理光标,在WM_SETCURSOR
消息的处理程序中,如果不是crDefault
,则它们显式设置屏幕光标,而忽略它们自己的光标。
因此,要更改行为,您可以处理上述消息。对于TButton
插入器,示例可能是:
procedure TButton.WMSetCursor(var Message: TWMSetCursor);
begin
if (Cursor <> crDefault) and (Message.HitTest = HTCLIENT) then begin
Message.Result := 1;
Windows.SetCursor(Screen.Cursors[Cursor]);
end else
inherited;
end;
图形控件的游标由其父级TWinControl
处理。因此,要更改速度按钮的行为,您仍然需要在其父按钮上处理相同的消息。由于父类可能事先未知,因此这可能是不切实际的。
还是非通用的实现,例如直接放置在表单上的图形控件的外观可能如下所示:
procedure TForm1.WMSetCursor(var Message: TWMSetCursor);
var
SmPt: TSmallPoint;
Control: TControl;
begin
DWORD(SmPt) := GetMessagePos;
Control := ControlAtPos(ScreenToClient(SmallPointToPoint(SmPt)),True);
if Assigned(Control) and Boolean(Control.Tag) then begin
Message.Result := 1;
Windows.SetCursor(Screen.Cursors[Control.Cursor])
end else
inherited;
end;
以上示例将要求图形控件具有非零标记值。例如:
procedure TForm1.Button1Click(Sender: TObject);
begin
Screen.Cursor := crHourGlass;
SpeedButton1.Cursor := crHandPoint;
SpeedButton1.Tag := 1;
end;
本文链接:https://www.f2er.com/2976296.html