怎样重画dbgrid网格线的颜色?谢谢!!(45分)

  • 主题发起人 主题发起人 wangchengwu
  • 开始时间 开始时间
W

wangchengwu

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样重画dbgrid网格线的颜色?谢谢!!
邮箱:ah_wcw@sohu.com
qq:57959940
 
可能用
dbgrid.color:=???
 
转!
可以的,摘自Grid.pas
加一个属性LineColor,重写下面的过程

procedure TCustomGrid.Paint;
var
LineColor: TColor;
...
begin
...
if ColorToRGB(Color) = clSilver then LineColor := clGray;
DrawLines(goFixedHorzLine in Options, goFixedVertLine in Options,
0, 0, [0, 0, Horz.FixedBoundary, Vert.FixedBoundary], clBlack, FixedColor);
DrawLines(goFixedHorzLine in Options, goFixedVertLine in Options,
LeftCol, 0, [Horz.FixedBoundary, 0, Horz.GridBoundary,
Vert.FixedBoundary], clBlack, FixedColor);
DrawLines(goFixedHorzLine in Options, goFixedVertLine in Options,
0, TopRow, [0, Vert.FixedBoundary, Horz.FixedBoundary,
Vert.GridBoundary], clBlack, FixedColor);
DrawLines(goHorzLine in Options, goVertLine in Options, LeftCol,
TopRow, [Horz.FixedBoundary, Vert.FixedBoundary, Horz.GridBoundary,
Vert.GridBoundary], LineColor, Color);

end;

 
转!
重写控件:
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;
或响应 OnDrawCell 事件:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
with StringGrid1 do
begin
Canvas.Pen.Color := clRed;
Canvas.MoveTo(Rect.Left - 1, Rect.Top);
Canvas.LineTo(Rect.Left - 1, Rect.Bottom);
end;
end;
 
up!!!!up!!!
 
在DBGrid控件中的DrawColumnCell的事件:
dbgrid2.Canvas.Pen.Width:=3;//设置线宽
dbgrid2.Canvas.Pen.Color := clRed;//设置颜色
//Rect.Left 为左上角X座标,Rect.Top为左上角Y座标
//Rect.Right为右下角X座标, Rect.Bottom为右下角Y座标
//以下画表格Cell的左边线
dbgrid2.Canvas.MoveTo(Rect.Left, Rect.Top);
dbgrid2.Canvas.LineTo(Rect.Left, Rect.Bottom);
//以下画表格Cell的上边线
dbgrid2.Canvas.Pen.Width:=3;//设置线宽
dbgrid2.Canvas.Pen.Color := clRed;//设置颜色
dbgrid2.Canvas.MoveTo(Rect.Left, Rect.Top);
dbgrid2.Canvas.LineTo(Rect.Right, Rect.Top);
 
后退
顶部