TStringGrid选中某行时改变字颜色和背景色,支持鼠标右键
goRangeSelect := false ; //不允许选择多行goRowSelect := true ; //选择行procedure Tfm_main.Grid2DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);var s: String; R: TRect;begin if ARow = Grid2.Row then begin TStringGrid(Sender).Canvas.Brush.Color := clmoneygreen; S := TStringGrid(Sender).Cells[ACol, ARow]; R := TStringGrid(Sender).CellRect(ACol, ARow); TStringGrid(Sender).Canvas.FillRect(R); TStringGrid(Sender).Canvas.Font.Color := clTeal ; TStringGrid(Sender).Canvas.TextOut(R.Left, R.Top, S); end;end;procedure Tfm_main.Grid2MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);var Cell: TGridCoord;begin try if (Button = mbRight) then begin Cell := Grid2.MouseCoord(X,Y); if (Cell.X >= 0) and (Cell.Y >= 1) then begin Grid2.Col := Cell.X; Grid2.Row := Cell.Y; end; end; except end;end;
?