procedure TFrmMain.StringGridDrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
var Area:TRect;
begin if not (TObject(MyList.Items[ListNo[1]]) is TStringGrid) then exit;
With Tstringgrid(MyList.Items[ListNo[1]]) do
begin
If ARow= 0 then
begin
Canvas.Brush.Color :=TempColor;// ClBlue;
Canvas.FillRect(Rect);
Canvas.font.color:=ClBlack;
Canvas.TextOut(rect.left , rect.top, cells[acol, arow]);
end;
end;
with Tstringgrid(MyList.Items[ListNo[1]]),Tstringgrid(MyList.Items[ListNo[1]]).Canvas do
begin
Brush.Style:=bsClear;
FillRect(Rect);
Area:= Rect;
InflateRect(Area, -2, -2); if (ARow=0) and (DT_flag=2) then
DrawText(Handle, PChar(Cells[ACol, ARow]),Length(Cells[ACol, ARow]), Area, DT_CENTER)
.............................我的Grid是动太生成的,OnDrawCell:=StringGridDrawCell;但运行时,Cell上的文字显示了两个,一次就是我设的居中,另外一次,可能是系统本身的DrawCell;
另外如果动态生成多个GRID的话,点到那个那个的标题栏色为黄色(我的DrawCell中设置的),不点为白色。
我想用我自己的DrawCell去override系统本身的。。告诉我这不是一个Base..不成功
请高手帮我。
ARow: Integer; Rect: TRect; State: TGridDrawState);
var Area:TRect;
begin if not (TObject(MyList.Items[ListNo[1]]) is TStringGrid) then exit;
With Tstringgrid(MyList.Items[ListNo[1]]) do
begin
If ARow= 0 then
begin
Canvas.Brush.Color :=TempColor;// ClBlue;
Canvas.FillRect(Rect);
Canvas.font.color:=ClBlack;
Canvas.TextOut(rect.left , rect.top, cells[acol, arow]);
end;
end;
with Tstringgrid(MyList.Items[ListNo[1]]),Tstringgrid(MyList.Items[ListNo[1]]).Canvas do
begin
Brush.Style:=bsClear;
FillRect(Rect);
Area:= Rect;
InflateRect(Area, -2, -2); if (ARow=0) and (DT_flag=2) then
DrawText(Handle, PChar(Cells[ACol, ARow]),Length(Cells[ACol, ARow]), Area, DT_CENTER)
.............................我的Grid是动太生成的,OnDrawCell:=StringGridDrawCell;但运行时,Cell上的文字显示了两个,一次就是我设的居中,另外一次,可能是系统本身的DrawCell;
另外如果动态生成多个GRID的话,点到那个那个的标题栏色为黄色(我的DrawCell中设置的),不点为白色。
我想用我自己的DrawCell去override系统本身的。。告诉我这不是一个Base..不成功
请高手帮我。
解决方案 »
- 在implementation中找不到DBlookupcomboboxclick方法?是什么原因呢
- RO, Remobjects读取数据速度的研究,希望高手指点一下。
- 关于继承中构造函数的一个问题
- <AI Techniques for Game Programming> 中文版出来了!
- 能否在QUERY控件中添加计算字段AA 合计QUERY某个字段的值
- 学海无涯,灌水无境。
- 哪里有Delphi组件下载?
- 卸载程序如何删除自身?
- 菜鸟问:怎样调用shellexcute来运行word、excel、图片 文档?
- 我的delphi 6 为什么不能用数据库呢?
- Delphi7里面如何发送一个XML文件到一个IP地址(端口)?
- 怎样导入*.dbf文件
2.在派生类中重写DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
3.不要用 DrawText(Handle, PChar(Cells[ACol, ARow]),Length(Cells[ACol, ARow]), Area, DT_CENTER)
改用这样的方式
var
si : tagSize;
cx : integer;
begin
....
si := Canvas.TextExtent(str);
cx := ARect.Left + (ARect.Right - ARect.Left - si.cx) div 2;
Canvas.TextRect(ARect, cx , ARect.Top + (ARect.Bottom - ARect.Top -si.cy) div 2 , str);
....
end;
这样就不会有两重字的出现了,(其实还是会每个格子画两次的,只是TextRect把上一次的东西清干净而已)。