这个线程讨论了在Virtual Treeview的同一节点中使用不同颜色的文本。
我特别喜欢变体C(白色文本在圆角红色矩形),但我希望它显示为ttStatic,而不是在自己的列-这是可能的吗?
您可以在事件"OndrawText"中编写以下代码:
procedure TForm2.vstDrawText(Sender: TBaseVirtualTree; TargetCanvas: TCanvas;
Node: PVirtualNode; Column: TColumnIndex; const Text: string;
const CellRect: TRect; var DefaultDraw: Boolean);
var ss1,ss2:string; POS:Integer; fc:TColor;fs:Integer;
begin
case Column of
0,1,3:
begin
//First, store the default font size and color number
fc:=TargetCanvas.Font.Color;
fs:=TargetCanvas.Font.Size;
DefaultDraw:=false;
ss1:=Text.Substring(0,3);
ss2:=Text.Substring(3);
pos:=5;
TargetCanvas.Font.Color:=clRed;
TargetCanvas.Font.size:=fs+2;
TargetCanvas.TextOut(CellRect.left+POS,4,ss1);
pos:=pos+targetcanvas.TextWidth(ss1)+2;
TargetCanvas.Font.Color:=fc;
TargetCanvas.Font.size:=fs;
TargetCanvas.TextOut(CellRect.left+POS,5,ss2);
end;
end;
end;