How to change mouse cursor icon when passing over link?

Asked

Viewed 1,524 times

8

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

The component I’m using in my table is the DBGrid.

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

How to do this?

  • Which version of Delphi are you using?

  • I’m using version XE4

  • Right, and what is this "Table" component you’re using? Wouldn’t it be a grid?

  • I am using Dbgrid

1 answer

8


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

You first have to declare a Type to access private properties:

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

And here 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;
  • +1 for the simplicity.

  • Very good...thanks, could I check if the field is empty ? If that person has not registered the email the cursor remains normal?

  • Pronto @Edder . see how to check updated solution

Browser other questions tagged

You are not signed in. Login or sign up in order to post.