Recent

Author Topic: [SOLVED] Hand cursor on VirtualDrawTree  (Read 788 times)

AsleyCruz

  • Full Member
  • ***
  • Posts: 118
    • Graphic and web designer
[SOLVED] Hand cursor on VirtualDrawTree
« on: April 21, 2023, 07:55:39 am »
Hi coders,

I am using the control VirtualDrawTree and would like to change the cursor to
crHandPoint on mouse over on a specified cell (not on whole control), column or node.

Please, help me with this task.

Thanks in advance.
« Last Edit: April 21, 2023, 08:39:59 pm by AsleyCruz »
Graphic & web designer

paweld

  • Hero Member
  • *****
  • Posts: 1561
Re: Hand cursor on VirtualDrawTree
« Reply #1 on: April 21, 2023, 11:01:28 am »
Something like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.vstMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  2. var
  3.   Node: PVirtualNode;
  4.   Data: PData;
  5. begin
  6.   if vst.Header.Columns.ColumnFromPosition(Point(X, Y)) = 2 then
  7.   begin
  8.     Node := vst.HotNode;
  9.     if Node <> nil then
  10.     begin
  11.       Data := vst.GetNodeData(Node);
  12.       if Data^.FSize > 1024 * 1024 then
  13.         vst.Cursor := crNo
  14.       else
  15.         vst.Cursor := crHandPoint;
  16.     end
  17.     else
  18.       vst.Cursor := crHandPoint;
  19.   end
  20.   else
  21.     vst.Cursor := crDefault;
  22. end;  
  23.  
 
Full sample in attachment
Best regards / Pozdrawiam
paweld

AsleyCruz

  • Full Member
  • ***
  • Posts: 118
    • Graphic and web designer
Re: Hand cursor on VirtualDrawTree
« Reply #2 on: April 21, 2023, 05:29:31 pm »
Something like this:

Thanks bro, worked like a charm.

One more question:
Is it possible to change the text color on mouse over on that column?

Well, hope it's possible. Thanks again
Graphic & web designer

paweld

  • Hero Member
  • *****
  • Posts: 1561
Re: Hand cursor on VirtualDrawTree
« Reply #3 on: April 21, 2023, 07:27:35 pm »
Code: Pascal  [Select][+][-]
  1. var
  2.   //...  
  3.   HotColumnIdx: Integer = -1;
  4.  
  5. procedure TForm1.vstDrawText(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; const CellText: String;
  6.   const CellRect: TRect; var DefaultDraw: Boolean);
  7. var
  8.   HotNode: PVirtualNode;
  9. begin
  10.   if (HotColumnIdx = 2) and (Column = 2) then
  11.   begin
  12.     HotNode := vst.HotNode;
  13.     if (HotNode <> nil) and (Node^.Index = Hotnode^.Index) then
  14.     begin
  15.       TargetCanvas.Font.Color := clWhite;
  16.       TargetCanvas.Font.Style := TargetCanvas.Font.Style + [fsBold];
  17.       TargetCanvas.Brush.Color := clBlack;
  18.     end;
  19.   end;
  20. end;
  21.  
  22. procedure TForm1.vstMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  23. var
  24.   Node: PVirtualNode;
  25.   Data: PData;
  26. begin
  27.   HotColumnIdx := vst.Header.Columns.ColumnFromPosition(Point(X, Y));
  28.   if HotColumnIdx = 2 then
  29.   begin
  30.     Node := vst.HotNode;
  31.     if Node <> nil then
  32.     begin
  33.       Data := vst.GetNodeData(Node);
  34.       if Data^.FSize > 1024 * 1024 then
  35.         vst.Cursor := crNo
  36.       else
  37.         vst.Cursor := crHandPoint;
  38.     end
  39.     else
  40.       vst.Cursor := crHandPoint;
  41.   end
  42.   else
  43.     vst.Cursor := crDefault;
  44. end;                    
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018