How to change mouse cursor icon when hovering over link?

8

Information: I have a table with employee data. There is a column of this table, where the emails are contained, they have a link that opens directly in Outlook .

The component I'm using in my table is DBGrid .

Purpose: I would like to change the mouse cursor icon when it is over the link, indicating that the email has a link.

How to do this?

    
asked by anonymous 12.02.2014 / 11:29

1 answer

8

Navigate to the events tab of your DBGrid and double-click OnMouseMove . Delphi will automatically create the event, you will check the X coordinate that would be the horizontal so it would be the column, so you should know what column would be the links in the emails, and if for example it was the column 3 it would check if it was empty and would set the Cursor, see how it would work:

You first have to declare Type to access private properties:

type
    THackGrid = class(TCustomDBGrid); //criar uma nova classe pra acessar as propriedades privadas

And here is the function of MouseMove :

procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);
var
  pt: TGridcoord;
  MouseScrPt : TPoint;
  OrigActiveRecord : integer;
begin
  pt:= DBGrid1.MouseCoord(x, y);

  if dgTitles in DBGrid1.Options    then  Dec(pt.y); //se o titulo é mostrado então ajusta a row index(-1) para nao dar erro de argument out of range
  if dgIndicator in DBGrid1.Options then  Dec(pt.x); //se o indicador é mostrado então ajusta a column index (-1) para nao dar erro de argument out of range

    if THackGrid(DBGrid1).DataLink.Active and (pt.y>=0) and (pt.x>=3)  then
    begin
       THackGrid(DBGrid1).DataLink.ActiveRecord:= pt.y;
       if (DBGrid1.Columns[pt.x].Field.AsString <> '') and (pt.x=3) then
         DBGrid1.Cursor:=crHandPoint
       else
         DBGrid1.Cursor:=crDefault;
    end;
end;
    
12.02.2014 / 12:09