delphi – 如何在VirtualTreeView中将单元格与背景图像进行颜色
发布时间:2020-12-15 10:13:07 所属栏目:大数据 来源:网络整理
导读:我正在使用VT.Background在VT中显示几列的背景图像. 但我无法找到一种方法为细胞使用不同的颜色,因为它们隐藏了背景图像. 我曾尝试使用OnBeforeItemErase但是如果我使用EraseAction:= eaColor,那么单元格上的背景位图区域也会被绘制,如果我使用eaDefault,则
|
我正在使用VT.Background在VT中显示几列的背景图像.
但我无法找到一种方法为细胞使用不同的颜色,因为它们隐藏了背景图像. 我曾尝试使用OnBeforeItemErase但是如果我使用EraseAction:= eaColor,那么单元格上的背景位图区域也会被绘制,如果我使用eaDefault,则不会应用颜色. 知道如何做到这一点? 解决方法
只是试图猜测你是否正在寻找:
更新: procedure ColorBlend(const ACanvas: HDC; const ARect: TRect;
const ABlendColor: TColor; const ABlendValue: Integer);
var
DC: HDC;
Brush: HBRUSH;
Bitmap: HBITMAP;
BlendFunction: TBlendFunction;
begin
DC := CreateCompatibleDC(ACanvas);
Bitmap := CreateCompatibleBitmap(ACanvas,ARect.Right - ARect.Left,ARect.Bottom - ARect.Top);
Brush := CreateSolidBrush(ColorToRGB(ABlendColor));
try
SelectObject(DC,Bitmap);
Windows.FillRect(DC,Rect(0,ARect.Bottom - ARect.Top),Brush);
BlendFunction.BlendOp := AC_SRC_OVER;
BlendFunction.BlendFlags := 0;
BlendFunction.AlphaFormat := 0;
BlendFunction.SourceConstantAlpha := ABlendValue;
Windows.AlphaBlend(ACanvas,ARect.Left,ARect.Top,ARect.Bottom - ARect.Top,DC,BlendFunction);
finally
DeleteObject(Brush);
DeleteObject(Bitmap);
DeleteDC(DC);
end;
end;
procedure TForm1.VirtualStringTree1BeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
BlendColor: TColor;
BlendValue: Integer;
begin
if CellPaintMode = cpmPaint then
begin
case Column of
0: BlendColor := $000080FF;
1: BlendColor := $0046C2FF;
2: BlendColor := $0046F5FF;
end;
BlendValue := 145;
if not VirtualTrees.MMXAvailable then
ColorBlend(TargetCanvas.Handle,CellRect,BlendColor,BlendValue)
else
VirtualTrees.Utils.AlphaBlend(0,TargetCanvas.Handle,Point(0,0),bmConstantAlphaAndColor,BlendValue,ColorToRGB(BlendColor));
end;
end;
预览上面的代码: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
