Recent

Author Topic: Cursorstyle change with mousemove in grid  (Read 2515 times)

flaza

  • Jr. Member
  • **
  • Posts: 59
Cursorstyle change with mousemove in grid
« on: November 05, 2014, 07:44:07 pm »
Hi.

I use a TStringgrid with 4 cols. The last col has buttonstyle cbsButtonColumn.
I want the cursor change to crHandpoint as the mouse moves along that column.
I created the method OnDrawCell with the content
Code: [Select]
procedure Form1.OnDrawCell(Sender: TObject; aCol, aRow: Integer;
  aRect: TRect; aState: TGridDrawState);
begin
  if (aCol = 3) and (gdHot in aState) then
    Screen.Cursor := crHandPoint
  else Screen.Cursor := crDefault;
end;
This works fine, except when I move the mouse upwards in the column.
Then the Cursor changes back to crDefault.
When I move the mouse downwards, the Cursor keeps showing as crHandpoint.

I've no idea why and how tot fix it.
Anyone? Thanks


howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Cursorstyle change with mousemove in grid
« Reply #1 on: November 05, 2014, 07:56:13 pm »
You picked the wrong event for achieving this effect. Try this (where the TStringGrid is named sg):

Code: [Select]
procedure TForm1.sgMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
  c, r: integer;
begin
  sg.MouseToCell(X, Y, c, r);
  if (c = 3) then
    Screen.Cursor := crHandPoint
  else Screen.Cursor := crDefault;
end;

flaza

  • Jr. Member
  • **
  • Posts: 59
Re: Cursorstyle change with mousemove in grid
« Reply #2 on: November 05, 2014, 08:30:24 pm »
That's it.
Thx.

 

TinyPortal © 2005-2018