在TListView中,系统默认选中某一项时,背景色是蓝色,字为白色,
我想把它的颜色改掉,但总是不行
我在CustomDrawItem事件里写
if Item.Selected then
begin
lvTests.Canvas.Brush.Color := clYellow
lvTests.Canvas.Font.Color := clBlack;
end
else begin
lvTests.Canvas.Brush.Color := clWindow;
lvTests.Canvas.Font.Color := clBlack;
end;
未选中的行可以更换颜色,而选项中的行的颜色始终为蓝色.
请大家帮忙
我想把它的颜色改掉,但总是不行
我在CustomDrawItem事件里写
if Item.Selected then
begin
lvTests.Canvas.Brush.Color := clYellow
lvTests.Canvas.Font.Color := clBlack;
end
else begin
lvTests.Canvas.Brush.Color := clWindow;
lvTests.Canvas.Font.Color := clBlack;
end;
未选中的行可以更换颜色,而选项中的行的颜色始终为蓝色.
请大家帮忙
解决方案 »
- 求助:记录类型累加
- 自己写的组件,如何初始化显示一个图片
- 线程操作ui,导致程序卡死问题
- 求高手开阔下思路:两个数组不一样长,取出不一样的元素
- VclSkin原理及相关问题
- 请问在delphi中怎么比较oracle中传出的以下数据的类型
- 如何解决vclskin按纽的颜色跟皮肤的颜色不一样
- 那位高手能帮我看一下这段代码,为什么总返出同样的值,是不是判断函数出错?
- quickreport 怎么打印出了空白页?
- 如何去掉twebbrowser右边恼人的ScrollBar ?
- ShellTreeView中怎样把选中的目录中的文件名称放到ListView中???
- 指定 TShellTreeView 的初始目录
Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
if (cdsSelected in State) then
begin
Sender.Canvas.Brush.Color :=clred;
Sender.Canvas.Font.Color :=clBlue;
end;
end;
刚写的,调试成功D7,看看是不是你要的??
Sender: TCustomListView; Item: TListItem; State: TCustomDrawState;
var DefaultDraw: Boolean);
var
R: TRect;
S: String;
x, y, i, j, m , n: Integer;
B: TBitmap;
begin
if Item = nil then Exit;
with Sender as TListView do
//只对选中的条目进行重画,其余用默认的
if (ViewStyle = vsReport) and Item.Selected and (Columns.Count > 0) then
begin
B := TBitmap.Create;
try
Canvas.Brush.Color := TD_COLOR_LISTVIEW_SELECTED;
Canvas.Font.Color := TD_COLOR_TEXT_NORMAL;
DefaultDraw := False;
//Canvas.Font.Style := [fsBold];
R.Top := Item.Position.Y;
R.Left := Item.Position.X;
//换成StateImages
//if (SmallImages <> nil) and (SmallImages.Count > 0) then
//begin
// SmallImages.GetBitmap(0, B);
// R.Left := R.Left + B.Width;
//end;
R.Bottom := R.Top + 20;
//最后一个Item高度减4, why?
if Item.Index = Items.Count - 1 then
R.Bottom := R.Bottom - 4;
//画左边的图标
R.Right := 0;
for i := 0 to Columns.Count - 1 do
R.Right := R.Right + Columns[i].Width;
//if (SmallImages <> nil) and (Item.ImageIndex <> -1) then
if (StateImages <> nil) and (Item.StateIndex <> -1) then
begin
//SmallImages.GetBitmap(Item.ImageIndex, B);
StateImages.GetBitmap(Item.StateIndex, B);
Canvas.Draw(2, R.Top, B);
end;
//填充整个Item的颜色
Canvas.FillRect(R);
x := R.Left + 2;
y := R.Top + 2;
//画Item的Caption
S := Item.Caption;
if S <> '' then Canvas.TextOut(x , y, S);
//画Item的所有SubItem
j := Columns[0].Width;
for i := 1 to Columns.Count - 1 do
begin
m := Columns[i].Width;
n := 0;
//画SubItem的图
if (SmallImages <> nil) and (Item.SubItemImages[i - 1] <> -1) then
begin
SmallImages.GetBitmap(Item.SubItemImages[i - 1], B);
Canvas.Draw(j, R.Top, B);
n := B.Width;
end;
S := Item.SubItems[i - 1];
if S <> '' then
begin
//居左
if Columns[i].Alignment = taLeftJustify then
begin
x := j + n + 6;
end
//居中
else if Columns[i].Alignment = taCenter then
begin
x := j + n + (m - Canvas.TextWidth(S)) div 2
end
//居右
else begin
x := j + n + m - Canvas.TextWidth(S)- 6;
end;
Canvas.TextOut(x, y, S);
end;
j := j + m;
end;
finally
B.Free;
end;
end
else begin
Canvas.Brush.Color := TD_COLOR_NORMAL;
Canvas.Font.Color := TD_COLOR_TEXT_NORMAL;
DefaultDraw := True;
end;
end;