我想更改虛擬字符串樹的特定行中文本的顏色。可能嗎?是否可以更改虛擬字符串樹中行的顏色?
回答
使用OnBeforeCellPaint事件:
procedure TForm1.VirtualStringTree1BeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
begin
if Node.Index mod 2 = 0 then
begin
TargetCanvas.Brush.Color := clFuchsia;
TargetCanvas.FillRect(CellRect);
end;
end;
這將改變背景上每隔一行(如果該行是在同一水平上)。
如果我不想要顏色,該怎麼辦?像刪除背景顏色我累了'TargetCanvas.Brush.Style:= bsClear;'但失敗 – MartinLoanel 2016-04-05 22:58:33
@MartinLoanel你需要做更多的事情來使整個控件變得透明。問這是一個不同的問題,你可能會得到一些答案或有人可能已經做到了。 – Nat 2016-04-13 00:51:23
已經找到了方法 – MartinLoanel 2016-04-13 12:36:05
要控制特定行中文本的顏色,請使用OnPaintText事件並設置TargetCanvas.Font.Color。
procedure TForm.TreePaintText(Sender: TBaseVirtualTree; const TargetCanvas:
TCanvas; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType);
var
YourRecord: PYourRecord;
begin
YourRecord := Sender.GetNodeData(Node);
// an example for checking the content of a specific record field
if YourRecord.Text = 'SampleText' then
TargetCanvas.Font.Color := clRed;
end;
請注意,此方法是爲TreeView中的每個單元調用的。節點指針在一行的每個單元中是相同的。因此,如果您有多個列,並且想要根據特定列的內容設置整行的顏色,則可以使用示例代碼中的給定節點。
要改變文本的顏色在一個特定的行,OnDrawText事件可用於在其中改變目前TargetCanvas.Font.Color財產。
下面的代碼可與德爾福XE 1和虛擬樹視圖5.5.2(http://virtual-treeview.googlecode.com/svn/branches/V5_stable/)
type
TFileVirtualNode = packed record
filePath: String;
exists: Boolean;
end;
PTFileVirtualNode = ^TFileVirtualNode ;
procedure TForm.TVirtualStringTree_OnDrawText(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode;
Column: TColumnIndex; const Text: UnicodeString; const CellRect: TRect; var DefaultDraw: Boolean);
var
pileVirtualNode: PTFileVirtualNode;
begin
pileVirtualNode:= Sender.GetNodeData(Node);
if not pileVirtualNode^.exists then
begin
TargetCanvas.Font.Color := clGrayText;
end;
end;
- 1. 如何在虛擬字符串樹節點上添加顏色?
- 2. 是否可以更改ScrollBar的顏色?
- 3. 是否可以更改Apple Map顏色?
- 4. 是否可以更改VS2015 Professional中的lambda操作符顏色?
- 5. 更改Java中的字符串顏色
- 6. 虛擬字符串樹中可能有多個標題行嗎?
- 7. 我可以更改克雷丁字符串的顏色嗎?
- 8. 是否有可能改變一個字符串顏色JOptionPane.showMessageDialog()
- 9. 更改特定字符串的顏色
- 10. 如何更改字符串的顏色
- 11. 是否可以更改Kdialog文字顏色?
- 12. 是否可以在運行時更改xterm「顏色表」?
- 13. java swing:是否可以改變特定字符串變量的顏色?
- 14. 以虛擬模式更改'DataGridView'的單元格背景顏色
- 15. 我們是否可以更改Android中的選項卡顏色
- 16. 是否可以更改wx.ListBox中項目的背景顏色?
- 17. 是否可以更改gridview中特定單元格的顏色?
- 18. 更改字符的顏色
- 19. 更改字符串顏色JavaMail
- 20. 是否可以更改HTML中的字體顏色和字體重量
- 21. 更改樹節點的字體顏色
- 22. 是否可以更改虛擬密鑰代碼?
- 23. 在Morris.js中,是否可以在單行中更改每個點的顏色?
- 24. 是否可以更改ListCtrl的「焦點選擇器」的顏色?
- 25. 是否可以更改Listview的FadingEdge的顏色?
- 26. 是否可以更改CMFCEditBrowseCtrl控件的背景顏色?
- 27. 是否可以更改Spyder Python控制檯的背景顏色?
- 28. 是否可以更改通知欄的顏色?
- 29. 是否可以更改高圖的背景顏色?
- 30. 是否可以更改特定x和y座標的顏色?
那麼,是你的問題回答? – Nat 2010-08-04 00:37:44