1
我在tvirtuailstringtree
繪製文本和圖像,如onbeforecellpaint
事件之後TVirtuailStringTree文字和圖像對齊
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;
什麼是'NewRect',在那裏,它是如何得到它的價值? 「XOffText」的含義是什麼(爲什麼它給出的值超出了'TextRectPlace'。你考慮過使用'DrawText()'而不是'TextOut()'嗎? –
使用textwidth函數來查看文本是否過長,然後縮小它的字符,直到它適合 – Dsm
NewRect是一個'TRect' var。xofftext使繪圖文本居中與圖像,drawtext將有所作爲? – Raelpaul