stringgrid
stringgrid
hallo, gibt es die möglichkeit bei einem stringgrid oder einer anderen ähnlichen komponente, die zeile unter dem mauszeiger zu markieren? (wie bei mousover oder tmainmenu)
- m.fuchs
- Lazarusforum e. V.
- Beiträge: 2807
- Registriert: Fr 22. Sep 2006, 19:32
- OS, Lazarus, FPC: Winux (Lazarus 2.0.10, FPC 3.2.0)
- CPU-Target: x86, x64, arm
- Wohnort: Berlin
- Kontaktdaten:
Re: stringgrid
Code: Alles auswählen
procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
Col, Row: Integer;
begin
StringGrid1.MouseToCell(X, Y, Col, Row);
StringGrid1.Selection := Rect(Col, Row, Col, Row);
end;
Software, Bibliotheken, Vorträge und mehr: https://www.ypa-software.de
Re: stringgrid
Ich würde lieber die Selection unangetastet lassen und die Mauszeile per OnPrepareCanvas einfärben:
Code: Alles auswählen
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Grids;
type
{ TForm1 }
TForm1 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
aState: TGridDrawState);
private
{ private declarations }
FMouseRow: Integer;
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
FMouseRow := -1;
end;
procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
colOfMouse, rowOfMouse: Integer;
begin
StringGrid1.MouseToCell(X, Y, colOfMouse, rowOfMouse);
if (rowOfMouse <> FMouseRow) and (rowOfMouse >= StringGrid1.FixedRows) then
begin
FMouseRow := rowOfMouse;
StringGrid1.Repaint;
end;
end;
procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
aState: TGridDrawState);
var
grid: TCustomGrid;
begin
grid := Sender as TCustomGrid;
if (aRow = FMouseRow) then
grid.Canvas.Brush.Color := DecColor(grid.Canvas.Brush.Color, 20);
end;
end.