dxdbgrid自画header后,caption不能居中显示,怎么处理一下 ( 积分: 50 )

  • 主题发起人 主题发起人 cooldren
  • 开始时间 开始时间
C

cooldren

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TMainFrm.dxDBGridCustomDrawColumnHeader(Sender: TObject;
AColumn: TdxTreeListColumn; ACanvas: TCanvas; ARect: TRect;
var AText: String; var AColor: TColor; AFont: TFont;
var AAlignment: TAlignment; var ASorted: TdxTreeListColumnSort;
var ADone: Boolean);
var
X, Y: Integer;
CustomDrawRgn: TdxCustomDrawRegion;
begin
CustomDrawRgn := TdxCustomDrawRegion.Create(ACanvas.Handle, ARect);
try
PaintImageTiled(ACanvas, ARect, Image2.Picture.Bitmap);

// ACanvas.Font.Size := 11;
X := ARect.Left + 5;
Y := ARect.Top + (ARect.Bottom - ARect.Top - ACanvas.TextHeight(AText)) div 2;

ACanvas.Brush.Color := clBtnFace;
ACanvas.Brush.Style := bsClear;

ACanvas.TextRect(ARect, X + 3, Y + 3, AText);

[red]// AColumn.HeaderAlignment:=taCenter;
// 上面这一句不行[/red]

DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDINNER, BF_TOPLEFT);
DrawEdge(ACanvas.Handle, ARect, BDR_RAISEDOUTER, BF_BOTTOMRIGHT);

finally
CustomDrawRgn.Free;
end;

ADone := True;

end;
 
已经解决
 
ACanvas.TextRect(ARect, X + 3, Y + 3, AText);
改成:
DrawText(ACanvas.Handle,PAnsiChar(AText),Length(AText),@ARect,DT_CENTER or DT_VCENTER);
 
后退
顶部