Recent

Author Topic: TDrawgrid: How change mousepointer hovering over cell depending on cellvalue  (Read 568 times)

WimVan

  • Jr. Member
  • **
  • Posts: 90
I'm looking for method, event, ... so when I hover over a cell with the mouse, the mousepointers changes depending on the value of that cell.
f.e;
When the cell is empty, the default pointervalue is used, when a cell contains a value, it changes to a handpoint.
I found nowhere some method activated by moving the mouse over a grid.

I added a simple prog in which 3 images are available to be showed in a drawgrind.  Added is an array 'pdfyes' which indicates that the concerned pdf is available.

How can I change the mousepointer, so that if the pointer becomes an crHandpoint when we hover over the cells and that the concerned pdf can be loaded.
Loading a pdf is already functioning.  The only thing I would change is the pointer.  On empty cells the default-value and only on the cover where the pdf is available (pdfyes) a handpoint-pointer should be present when we hover over that cell, image.

Code: Pascal  [Select][+][-]
  1. unit test_shoot_01;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Grids, Types;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     shootgrid: TDrawGrid;
  16.     procedure FormCreate(Sender: TObject);
  17.     procedure shootgridDrawCell(Sender: TObject; aCol, aRow: Integer;
  18.       aRect: TRect; aState: TGridDrawState);
  19.   private
  20.  
  21.   public
  22.  
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.   coverlist        : array of TPicture;
  28.   pdfyes           : array of boolean;
  29.   cover_index      : integer;
  30.   cover_index_nr   : integer;
  31.  
  32. implementation
  33.  
  34. {$R *.lfm}
  35.  
  36. { TForm1 }
  37.  
  38. procedure TForm1.FormCreate(Sender: TObject);
  39. begin
  40.   setlength( coverlist, 3 );
  41.   setlength( pdfyes, 3 );
  42.   coverlist[ 0 ] := TPicture.Create;
  43.   coverlist[ 0 ].LoadFromFile('shoot01.jpg');
  44.   coverlist[ 1 ] := TPicture.Create;
  45.   coverlist[ 1 ].LoadFromFile('shoot02.jpg');
  46.   coverlist[ 2 ] := TPicture.Create;
  47.   coverlist[ 2 ].LoadFromFile('shoot03.jpg');
  48.   cover_index    := length( coverlist );
  49.  
  50.   pdfyes[ 0 ]  := true;
  51.   pdfyes[ 1 ]  := false;
  52.   pdfyes[ 2 ]  := true;
  53.  
  54. end;
  55.  
  56. procedure TForm1.shootgridDrawCell(Sender: TObject; aCol, aRow: Integer;
  57.   aRect: TRect; aState: TGridDrawState);
  58. var
  59.   R       : TRect;
  60.   ncel    : integer;
  61.   TheGrid : TDrawGrid;
  62. begin
  63.   TheGrid := Sender as TDrawGrid;
  64.   if cover_index > 0
  65.   then
  66.   begin
  67.     ncel := aCol + (aRow * TheGrid.ColCount) + 1;
  68.  
  69. //showmessage( inttostr( ncel - 1) + chr(10) + inttostr( cover_index) );
  70.     if ncel <= cover_index
  71.     then
  72.     begin
  73.       R        := aRect;
  74.       R.Top    := aRect.Top + 3;
  75.       R.Bottom := R.Top + coverlist[ ncel - 1 ].Height;
  76.       R.Left   := aRect.Left + (aRect.Width - coverlist[ ncel - 1 ].Width) div 2;
  77.       R.Right  := R.Left + coverlist[ ncel - 1 ].Width;
  78.       TheGrid.Canvas.StretchDraw( R, coverlist[ ncel - 1 ].Graphic   );
  79.     end;
  80.   end;
  81. end;
  82.  
  83. end.
  84.  
  85.  

paweld

  • Hero Member
  • *****
  • Posts: 1561
Code: Pascal  [Select][+][-]
  1. procedure TForm1.shootgridMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
  2. var
  3.   aCol, aRow: Integer;
  4.   ncel: integer;
  5.   TheGrid: TDrawGrid;
  6. begin
  7.   TheGrid := Sender as TDrawGrid;
  8.   TheGrid.MouseToCell(X, Y, aCol, aRow);
  9.   ncel := aCol + (aRow * TheGrid.ColCount);
  10.   Caption := IntToStr(ncel);
  11.   if (ncel < cover_index) and (cover_index > 0) then
  12.   begin
  13.     if pdfyes[ncel] then
  14.       TheGrid.Cursor := crHandPoint
  15.     else
  16.       TheGrid.Cursor := crNo;
  17.   end
  18.   else
  19.     TheGrid.Cursor := crDefault;
  20. end;  
« Last Edit: January 18, 2023, 03:13:07 pm by paweld »
Best regards / Pozdrawiam
paweld

WimVan

  • Jr. Member
  • **
  • Posts: 90
Thx,
now I reallize I always overlooked the onmousemove-event  >:(
I looked for more than 3 days to solve this problem whom is not really one ...  Think I'll have to sleep a little more so that I'm more concentrated on all possible events ...

 

TinyPortal © 2005-2018