RzListView自带了OnDrawHeader 事件,在该事件中进行自绘即可。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,CommCtrl, ComCtrls, ProgressBarEx, StdCtrls, URLLabel, RzListVw;
type
TForm1 = class(TForm)
RzListView1: TRzListView;
procedure FormCreate(Sender: TObject);
procedure RzListView1DrawHeader(Sender: TObject; Canvas: TCanvas;
Index: Integer; Rect: TRect);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i, j: integer;
lit: TListItem;
begin
with RzListView1 do
for i := 0 to 5 do
begin
Columns.Add.Caption := 'Column' + IntToStr(i);
Columns[i].Width := 70;
lit := Items.Add;
lit.Caption := 'Item' + IntToStr(i);
for j := 1 to 5 do
lit.SubItems.Add('SubItem' + IntToStr(j) + IntToStr(i))
end
end;
procedure TForm1.RzListView1DrawHeader(Sender: TObject; Canvas: TCanvas; Index: Integer; Rect: TRect);
procedure ADrawText(Canvas: TCanvas; AText: string; ARect: TRect);
var
H, W, X, Y: Integer;
begin
Canvas.Brush.Style := bsClear;
Canvas.Font.Color := clWhite;
//Canvas.Font.Name := '微软雅黑';
//Canvas.Font.Size := 18;
H := Canvas.TextHeight('a');
W := Canvas.TextWidth(AText);
X := ARect.Left + (ARect.Right - ARect.Left - W) div 2;
Y := ARect.Top + (ARect.Bottom - ARect.top - H) div 2;
if X < ARect.Left then
X := ARect.Left;
Canvas.TextOut(X, Y, AText);
end;
var
bmp : TBitmap;
Str: string;
ARect: TRect;
begin
bmp := TBitmap.Create;
try
bmp.SetSize(1, Rect.Bottom - Rect.Top);
bmp.Canvas.Brush.Color := clblue;
bmp.Canvas.FillRect(bmp.Canvas.ClipRect);
ARect := Rect;
if Index = RzListView1.Columns.Count - 1 then
begin
ARect.Right := ARect.Right
end;
Canvas.StretchDraw(ARect, bmp);
{画分隔线}
Canvas.Pen.Color := $00838383;
Canvas.MoveTo(ARect.Right - 1, ARect.Top + 1);
Canvas.LineTo(ARect.Right - 1, ARect.Bottom - 1);
// if Index = 0 then
// begin
// Canvas.Pen.Color := $FF6E6E6E;
// Canvas.MoveTo(ARect.Left , ARect.Top + 1);
// Canvas.LineTo(ARect.Left , ARect.Bottom - 1);
// end;
Str := RzListView1.Columns[Index].Caption;
ADrawText(Canvas, Str, ARect);
finally
bmp.Free;
end;
end;
end.
示例效果如下截图:
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/139921.html