[Lazarus] Stringgrid ?

Bart bartjunk64 at gmail.com
Sun Nov 18 00:11:20 CET 2012


On 11/17/12, Terry A. Haimann <terry at haimannonline.com> wrote:

> You know that's not a lot of help.

Thank you very much ;-)

> If you know how to  do this,
> why can't you provide a snippet of code with maybe a few comments?

This is from one of my programs.
It changes color of background of a cell when the mouse hoovers over it.
The relevat code is in EntityGridPrepareCanvas (as Juha suggested)
(The other code is just to select the cell the mouse is hoovering over.)
I leave it up to you to change font color...

procedure THtmlCharmapForm.EntityGridMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  Row, Col, Idx: Integer;
  S: String;
begin
  //debugln('THtmlCharmapForm.EntityGridMouseDown');
  if (Button = mbLeft) and (EntityGrid.MouseToGridZone(X, Y) = gzNormal) then
  begin
    EntityGrid.MouseToCell(X, Y, Col, Row);
    //debugln('  Col = ',dbgs(col),' Row = ',dbgs(row));
    Idx := RowColToIndex(Row, Col);
    //debugln('  Idx = ',dbgs(idx));
    S := HtmlEntityFromIndex(SelectionBox.ItemIndex, Idx);
    //debugln('  S = ',S);
    DoOnHtmlCharClick(S);
  end;
end;

procedure THtmlCharmapForm.EntityGridMouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
var
  Row, Col, Idx: Integer;
  S: String;
begin
  //debugln('THtmlCharmapForm.EntityGridMouseMove');
  if (EntityGrid.MouseToGridZone(X, Y) = gzNormal) then
  begin
    EntityGrid.MouseToCell(X, Y, Col, Row);
    //debugln('  Col = ',dbgs(col),' Row = ',dbgs(row));
    Idx := RowColToIndex(Row, Col);
    //debugln('  Idx = ',dbgs(idx));
    S := HtmlEntityFromIndex(SelectionBox.ItemIndex, Idx);
    //debugln('  S = ',S);
    EntityGrid.Row := Row;
    EntityGrid.Col := Col;
    ExampleLabel.Caption := S;
  end;
end;

procedure THtmlCharmapForm.EntityGridPrepareCanvas(sender: TObject; aCol,
  aRow: Integer; aState: TGridDrawState);
begin
  if (gdSelected in aState) then
  begin
    EntityGrid.Canvas.Brush.Color := clLime;
  end
end;

Bart




More information about the Lazarus mailing list