我正在tvirtuailstringtree
中绘制文字和图片,如onbeforecellpaint
事件
begin
Textrectplace := NewRect;
Textrectplace.Left := Textrectplace.Left + 2;
Textrectplace.Width := 24;
Textrectplace.Height := Data.image.height;
Textrectplace.Top := Textrectplace.Top;
Textrectplace.Bottom := Textrectplace.Bottom;
xOfftext := Textrectplace.Left + Textrectplace.Width + 4;
yOfftext := Textrectplace.Top - 3 + ((Data.image.height - TargetCanvas.TextHeight('H')) div 2);
TargetCanvas.font.color := clgray;
TargetCanvas.font.Size := 10;
TargetCanvas.TextOut(xOfftext, yOfftext, Data.text);
end;
end;
begin
imgrect:= Textrectplace;
imgrect.Left := imgrect.Left + 150;
imgrect.Width := 24;
imgrect.Height := 36;
imgrect.Top := imgrect.Top - 6 + ((Data.image.height - TargetCanvas.TextHeight('H')) div 2);
imgrect.Bottom := imgrect.Bottom;
TargetCanvas.Draw(imgrect.Left, imgrect.Top, Data.image);
end;
我在文本和图像对齐方面有一个问题我希望文本对齐到左边并处理该部分。图像有对齐问题我想让它与当前没有textoverflow
的文本对齐,如果节点的短文本全部正常,图像正确显示文本。但是如果文字太长了overflow
图片。
这里是示例图片
在图像示例中它显示了长文本节点的样子以及如果文本太长而且列表宽度小以使图像与文本对齐时它应该如何显示我很长点头...... 直到列表变大,然后显示全文我是长节点文本我该如何实现
更新代码
procedure TForm1.virtuailtreeBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
var
Data: ^PnodeData;
NewRect: TRect;
Textrectplace: TRect;
imgrect : TRect;
begin
if not Assigned(Node) then
begin
exit;
end;
Data := virtuailtree.GetNodeData(Node);
NewRect := CellRect;
//text
begin
Textrectplace := NewRect;
Textrectplace.Left := Textrectplace.Left + 2;
Textrectplace.Width := 70;
Textrectplace.Height := 30;
Textrectplace.Top := Textrectplace.Top;
Textrectplace.Bottom := Textrectplace.Bottom;
TargetCanvas.font.color := clgray;
TargetCanvas.font.Size := 10;
DrawText(TargetCanvas.Handle, pChar(Data.text), Length(Data.text)
, Textrectplace, DT_End_Ellipsis );
end;
end;
//right image that should be stay at the right position
begin
imgrect := Textrectplace;
imgrect.left := imgrect.left + 150;
imgrect.Width := 24;
imgrect.Height := 36;
imgrect.Top := imgrect.Top - 6 + ((30 - TargetCanvas.TextHeight('H')) div 2);
imgrect.Bottom := imgrect.Bottom;
TargetCanvas.Draw(imgrect.left, imgrect.Top, Data.image);
end;
end;
答案 0 :(得分:1)
要缩短文本以适应TRect
,您可以使用带有DT_END_ELLIPSIS
格式说明符的WinApi DrawText()
函数。
要在TVirtualStringTree
调整大小时调整文本空间(例如使用TSplitter
),只需使用:
TextRectPlace.Right := CellRect - imgRect.width;
imgRect.Left := TextRectPlace.Right;
答案 1 :(得分:0)
此示例显示如何使列单元格和标题文本向左对齐,单元格图像向右对齐:
VirtualStringTree1.Alignment := taLeftJustify;
VirtualStringTree1.BiDiMode := bdLeftToRight;
VirtualStringTree1.Header.Columns[ 0 ].Alignment := taRightJustify;
VirtualStringTree1.Header.Columns[ 0 ].BiDiMode := bdRightToLeftNoAlign;
VirtualStringTree1.Header.Columns[ 0 ].CaptionAlignment := taRightJustify;