L
lyco
Unregistered / Unconfirmed
GUEST, unregistred user!
在TreeView里面,为了实现“RichText”的效果,我自己向Canvas上面写字,可是为什么我
在第一次设置了字体之后,后面的所有汉字都是按找第一次设定的字体来写的呢?
我的代码如下:
procedure TForm1.TreeView1advancedCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
var PaintImages, DefaultDraw: Boolean);
var
NRect: TRect;
TextPlace: Integer;
procedure DrawText(CurCanvas: TCanvas; TextColor: TColor; TextFontStyles: TFontStyles; Text: WideString;
Top: Integer; var NewTextLeft: Integer);
begin
with CurCanvas do
begin
Font.Color := TextColor;
Font.Style := TextFontStyles;
TextOut(NewTextLeft, NRect.Top, Text);
Inc(NewTextLeft, TextWidth(Text));
end;
end;
begin
if (Stage = cdPostPaint) then
begin
NRect := Node.DisplayRect(True);
TextPlace := NRect.Left;
DrawText(Sender.Canvas, clBlue, [fsBold], '粗体', NRect.Top, TextPlace);
DrawText(Sender.Canvas, clRed, [fsUnderline], '下划线', NRect.Top, TextPlace);
DrawText(Sender.Canvas, clBlue, [fsItalic], ' 斜体', NRect.Top, TextPlace);
end;
end;
其中,内部函数GrawText利用传入的颜色和字体来写传入的字符串,可是,所有的字符串都是按照第一次设定的内容来写的,都是蓝色,粗体,好奇怪啊
谁知道怎么回事吗?
在第一次设置了字体之后,后面的所有汉字都是按找第一次设定的字体来写的呢?
我的代码如下:
procedure TForm1.TreeView1advancedCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
var PaintImages, DefaultDraw: Boolean);
var
NRect: TRect;
TextPlace: Integer;
procedure DrawText(CurCanvas: TCanvas; TextColor: TColor; TextFontStyles: TFontStyles; Text: WideString;
Top: Integer; var NewTextLeft: Integer);
begin
with CurCanvas do
begin
Font.Color := TextColor;
Font.Style := TextFontStyles;
TextOut(NewTextLeft, NRect.Top, Text);
Inc(NewTextLeft, TextWidth(Text));
end;
end;
begin
if (Stage = cdPostPaint) then
begin
NRect := Node.DisplayRect(True);
TextPlace := NRect.Left;
DrawText(Sender.Canvas, clBlue, [fsBold], '粗体', NRect.Top, TextPlace);
DrawText(Sender.Canvas, clRed, [fsUnderline], '下划线', NRect.Top, TextPlace);
DrawText(Sender.Canvas, clBlue, [fsItalic], ' 斜体', NRect.Top, TextPlace);
end;
end;
其中,内部函数GrawText利用传入的颜色和字体来写传入的字符串,可是,所有的字符串都是按照第一次设定的内容来写的,都是蓝色,粗体,好奇怪啊
谁知道怎么回事吗?