本文介绍了在的ListView项目和行vsReport着色模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要灰色和其他在白色变为彩色一行。结果
我有以下的code,但没有在Windows 7中的搜索栏的垂直线空白
我如何颜色的所有行?
程序TForm2.Update_ListBoxCustomDrawItem(发件人:TCustomListView;
项目:TListItem;状态:TCustomDrawState; VAR DefaultDraw:布尔);
开始
如果Item.Index模2 = 0
然后
开始
Sender.Canvas.Font.Color:= clBlack;
Sender.Canvas.Brush.Color:= $ F6F6F6;
结束
其他
开始
Sender.Canvas.Font.Color:= clBlack;
Sender.Canvas.Brush.Color:= clWhite;
结束;
结束;
解决方案
设置的OwnerDraw
到真正
并添加
程序TForm1.ListView1DrawItem(发件人:TCustomListView;项目:TListItem;
RECT:TRect;状态:TOwnerDrawState);
VAR
我:整数;
X1,X2:整数;
R:TRect;
小号:字符串;
常量
DT_ALIGN:数组整数[TAlignment] =(DT_LEFT,DT_RIGHT,DT_CENTER);
开始
如果奇(Item.Index),然后
开始
Sender.Canvas.Font.Color:= clBlack;
Sender.Canvas.Brush.Color:= $ F6F6F6;
结束
其他
开始
Sender.Canvas.Font.Color:= clBlack;
Sender.Canvas.Brush.Color:= clWhite;
结束;
Sender.Canvas.Brush.Style:= bsSolid;
Sender.Canvas.FillRect(矩形);
X1:= 0;
X2:= 0;
R:=矩形;
Sender.Canvas.Brush.Style:= bsClear;
对于i:= 0 ListView1.Columns.Count - 1做
开始
增量(2次,ListView1.Columns [I] .WIDTH);
r.Left:= X1;
r.Right:= X2;
若i = 0,则
小号:= Item.Caption
其他
小号:= Item.SubItems [I]
DrawText的(Sender.Canvas.Handle,
S,
长度(S),
R,
DT_SINGLELINE或DT_ALIGN [ListView1.Columns [I] .Alignment]或
DT_VCENTER或DT_END_ELLIPSIS);
X1:= X2;
结束;
结束;
在上面的例子中,第一列是左对齐并且两个其他居中
如果你只有一列,那就是无子:
程序TForm1.ListView1DrawItem(发件人:TCustomListView;项目:TListItem;
RECT:TRect;状态:TOwnerDrawState);
VAR
R:TRect;
小号:字符串;
常量
DT_ALIGN:数组整数[TAlignment] =(DT_LEFT,DT_RIGHT,DT_CENTER);
开始
如果奇(Item.Index),然后
开始
Sender.Canvas.Font.Color:= clBlack;
Sender.Canvas.Brush.Color:= $ F6F6F6;
结束
其他
开始
Sender.Canvas.Font.Color:= clBlack;
Sender.Canvas.Brush.Color:= clWhite;
结束;
Sender.Canvas.Brush.Style:= bsSolid;
Sender.Canvas.FillRect(矩形);
R:=矩形;
Sender.Canvas.Brush.Style:= bsClear;
小号:= Item.Caption;
DrawText的(Sender.Canvas.Handle,
S,
长度(S),
R,
DT_SINGLELINE或DT_ALIGN [ListView1.Columns [0] .Alignment]或DT_VCENTER或DT_END_ELLIPSIS);
结束;
I want to color one row in gray and the other in white.
I have the following code but there is white space of vertical lines of columns in Windows 7.
How do I color all rows?
procedure TForm2.Update_ListBoxCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if Item.Index mod 2=0
then
begin
Sender.Canvas.Font.Color:=clBlack;
Sender.Canvas.Brush.Color:=$F6F6F6;
end
else
begin
Sender.Canvas.Font.Color:=clBlack;
Sender.Canvas.Brush.Color:=clWhite;
end;
end;
解决方案
Set OwnerDraw
to true
and add
procedure TForm1.ListView1DrawItem(Sender: TCustomListView; Item: TListItem;
Rect: TRect; State: TOwnerDrawState);
var
i: Integer;
x1, x2: integer;
r: TRect;
S: string;
const
DT_ALIGN: array[TAlignment] of integer = (DT_LEFT, DT_RIGHT, DT_CENTER);
begin
if Odd(Item.Index) then
begin
Sender.Canvas.Font.Color := clBlack;
Sender.Canvas.Brush.Color := $F6F6F6;
end
else
begin
Sender.Canvas.Font.Color := clBlack;
Sender.Canvas.Brush.Color := clWhite;
end;
Sender.Canvas.Brush.Style := bsSolid;
Sender.Canvas.FillRect(Rect);
x1 := 0;
x2 := 0;
r := Rect;
Sender.Canvas.Brush.Style := bsClear;
for i := 0 to ListView1.Columns.Count - 1 do
begin
inc(x2, ListView1.Columns[i].Width);
r.Left := x1;
r.Right := x2;
if i = 0 then
S := Item.Caption
else
S := Item.SubItems[i];
DrawText(Sender.Canvas.Handle,
S,
length(S),
r,
DT_SINGLELINE or DT_ALIGN[ListView1.Columns[i].Alignment] or
DT_VCENTER or DT_END_ELLIPSIS);
x1 := x2;
end;
end;
In the above example, the first column is left-aligned and the two other are centered.
If you only have one column, that is, no subitems:
procedure TForm1.ListView1DrawItem(Sender: TCustomListView; Item: TListItem;
Rect: TRect; State: TOwnerDrawState);
var
r: TRect;
S: string;
const
DT_ALIGN: array[TAlignment] of integer = (DT_LEFT, DT_RIGHT, DT_CENTER);
begin
if odd(Item.Index) then
begin
Sender.Canvas.Font.Color:=clBlack;
Sender.Canvas.Brush.Color:=$F6F6F6;
end
else
begin
Sender.Canvas.Font.Color:=clBlack;
Sender.Canvas.Brush.Color:=clWhite;
end;
Sender.Canvas.Brush.Style := bsSolid;
Sender.Canvas.FillRect(Rect);
r := Rect;
Sender.Canvas.Brush.Style := bsClear;
S := Item.Caption;
DrawText(Sender.Canvas.Handle,
S,
length(S),
r,
DT_SINGLELINE or DT_ALIGN[ListView1.Columns[0].Alignment] or DT_VCENTER or DT_END_ELLIPSIS);
end;
这篇关于在的ListView项目和行vsReport着色模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!