2012-11-28 12 views
5

मैं डेल्फी एक्सई -3 का उपयोग कर रहा हूं। मैं चेकलिस्टबॉक्स में एक ही आइटम के रंग या फ़ॉन्ट में बदलना चाहता हूं। क्या यह संभव है?किसी विशिष्ट चेकलिस्टबॉक्स आइटम का फ़ॉन्ट या रंग बदलना?

+0

या अनुकरण checklistbox बुद्धि h3rd पक्ष VTW –

+0

इसी तरह नियंत्रण/करने के लिए http नकल : //stackoverflow.com/questions/8563508/how-do-i-draw-the- चयनित-list-box-item-in-a- अलग-color –

उत्तर

10

आपको अपने चेक सूची बॉक्स के लिए मालिक ड्राइंग का उपयोग करने की आवश्यकता होगी। Style अपनी चेक सूची बॉक्स की संपत्ति lbOwnerDrawFixed पर सेट करें और OnDrawItem ईवेंट के लिए हैंडलर लिखें।

procedure TForm1.CheckListBox1DrawItem(Control: TWinControl; Index: Integer; 
    Rect: TRect; State: TOwnerDrawState); 
var 
    Flags: Longint; 
begin 
    with (Control as TCheckListBox) do 
    begin 
    // modifying the Canvas.Brush.Color here will adjust the item color 
    case Index of 
     0: Canvas.Brush.Color := $00F9F9F9; 
     1: Canvas.Brush.Color := $00EFEFEF; 
     2: Canvas.Brush.Color := $00E5E5E5; 
    end; 
    Canvas.FillRect(Rect); 
    // modifying the Canvas.Font.Color here will adjust the item font color 
    case Index of 
     0: Canvas.Font.Color := clRed; 
     1: Canvas.Font.Color := clGreen; 
     2: Canvas.Font.Color := clBlue; 
    end; 
    Flags := DrawTextBiDiModeFlags(DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX); 
    if not UseRightToLeftAlignment then 
     Inc(Rect.Left, 2) 
    else 
     Dec(Rect.Right, 2); 
    DrawText(Canvas.Handle, Items[Index], Length(Items[Index]), Rect, Flags); 
    end; 
end; 

यहाँ ऊपर के उदाहरण का परिणाम है: इस ईवेंट हैंडलर में आप कुछ इस तरह का उपयोग कर सकते

enter image description here

+6

यह आइटम की स्थिति को कवर नहीं करता है (यदि यह केंद्रित है , चयनित या नहीं) और वीसीएल शैलियों को अनदेखा करता है। – TLama

संबंधित मुद्दे