2010-07-23 5 views
11

मैं वर्चुअल स्ट्रिंग पेड़ की एक विशिष्ट पंक्ति में टेक्स्ट का रंग बदलना चाहता हूं। क्या यह संभव है?वर्चुअल स्ट्रिंग पेड़ में पंक्ति के रंग को बदलना संभव है?

+0

तो साथ काम करता है, अपने प्रश्न का उत्तर है? – Nat

उत्तर

8

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; 

यह (यदि पंक्तियों एक ही स्तर पर कर रहे हैं) हर दूसरे पंक्ति पर पृष्ठभूमि बदल जाएगा।

+0

क्या होगा अगर मुझे बिल्कुल रंग नहीं चाहिए? जैसे बैक ग्राउंड रंग को हटा दें, मैं थक गया 'TargetCanvas.brush.Style: = bsClear;' लेकिन असफल – MartinLoanel

+1

@ मार्टिन लोनेल आपको पूरे नियंत्रण को पारदर्शी बनाने के लिए बहुत कुछ करने की आवश्यकता होगी। एक अलग प्रश्न के रूप में पूछें और आपको कुछ जवाब मिल सकते हैं या कोई इसे पहले से ही कर सकता है। – Nat

+0

पहले से ही एक रास्ता खोजने के लिए – MartinLoanel

7

किसी विशिष्ट पंक्ति में टेक्स्ट के रंग को नियंत्रित करने के लिए, 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 में प्रत्येक सेल के लिए बुलाया जाता है। नोड पॉइंटर एक पंक्ति के प्रत्येक सेल में समान है। तो यदि आपके पास एकाधिक कॉलम हैं और एक विशिष्ट कॉलम की सामग्री को भरने वाली पूरी पंक्ति के लिए रंग सेट करना चाहते हैं, तो आप दिए गए नोड का उपयोग उदाहरण कोड में कर सकते हैं।

0

एक विशिष्ट पंक्ति में पाठ का रंग बदलने के लिए, OnDrawText घटना इस्तेमाल किया जा सकता है जिसमें आप वर्तमान TargetCanvas.Font.Color संपत्ति बदल जाते हैं।

नीचे कोड डेल्फी XE 1 और आभासी treeview 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; 
संबंधित मुद्दे