修改DBGrid的表格线颜色。(100分)

  • 主题发起人 主题发起人 aerobull
  • 开始时间 开始时间
A

aerobull

Unregistered / Unconfirmed
GUEST, unregistred user!
如何修改DBGrid中表格线的颜色。
急!
 
下载一个离线吧。
 
要改它的颜色的话,照我的思路一般是会去看看DBGrid中在哪画这么表格线的
找一找,
在这里吧:
procedure TCustomDBGrid.DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
......
if (gdFixed in AState) and ([dgRowLines, dgColLines] * Options =
[dgRowLines, dgColLines]) then
begin
InflateRect(ARect, 1, 1);
DrawEdge(Canvas.Handle, ARect, BDR_RAISEDINNER, BF_BOTTOMRIGHT);
DrawEdge(Canvas.Handle, ARect, BDR_RAISEDINNER, BF_TOPLEFT);
end;
应该就在这里画的,
具体流程,我也没仔细看了;)

看看过程的定义:
TCustomDBGrid = class(TCustomGrid)
......
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;

那就自己定义一个试试吧:
TMyDBGrid = class(TCustomDBGrid)
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState); override;

end;
{ TMyDBGrid }

procedure TMyDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
begin
inherited;

//表头还是不要重画了吧
if (acol<1) or (arow<1) then exit;

if {(gdFixed in AState) and }([dgRowLines, dgColLines] * Options =
[dgRowLines, dgColLines]) then
begin
//设置要画的线条颜色
self.Canvas.Pen.Color:=clred;
//设定所画表格线的范围
InflateRect(ARect, 1, 0);
//覆盖原来画的
canvas.Polyline([point(arect.Left,arect.Top),point(arect.Left,arect.Bottom),point(arect.Right,arect.Bottom),point(arect.Right,arect.Top)]);
end;

end;

试一把看看:
procedure TForm1.Button1Click(Sender: TObject);
begin
table1.open;

if MyDBGrid=nil then
begin
MyDBGrid:=TMyDBGrid.Create(self);
with MyDBGrid do
begin
parent:=self;
top:=150;
left:=50;
Datasource:=datasource1;
end;
end;
end;
好象可以了。
当然,你可以加属性来修改颜色,线宽,线型(线型不同可能需要先清一下原表格线区域)
 
接受答案了.
 
后退
顶部