2011-08-12 10 views
1

私はちょうどDelphiのTMS Componentsをインストールしました。TAdvSmoothListBox各項目の色をカスタマイズしたいと思います。TAdvSmoothListBoxの項目の色をカスタマイズする

私は実際に.ItemAppearance.Fill.Colorを使用していますが、すべてのアイテムを同じ色で塗りつぶします。

どのように各アイテムの色を個別に設定する方法を教えていただけますか?私はDaemon_xはここだと思う

おかげ

+0

'TAdvSmoothListBox.DefaultDrawを設定してください:

これはあなたのOnItemBkgDrawハンドラです。現時点ではTMSスイートがなく、イベントハンドラを知らないので、私はあなたにもっと助けられません。 –

答えて

1

は、私はあなたがデフォルトでTAdvSmoothlistboxのプロパティ/メソッドでこれを行うことができると思ういけません。

フォントや画像などは簡単に変更できますが、背景色はOnItemBkgDrawおよび/またはOnItemDrawイベントを使用して行う必要があります。 (バージョン2.4.0.1のように)

+0

これは、どのように各項目をカスタマイズするかの方法だとは思いますが、イベントハンドラのパラメータがわからないため、例を示すことはできません。私はそれがイベントパラメータによって調整可能であると確信しています。私は一番早い日曜日に私のD2009に行きます。以前にお手伝いしたい方には、D2009、D2010、およびDXEユーザーのために[TMS Smooth Controls]スイートが[Embarcadero](http://cc.embarcadero.com/reg/delphi)で無料で提供されていることを思い出させていただきますが、残念ながらソースコードなし。 –

2

イベントOnItemBkgDrawは、あなたが背景を自分で描くために必要なものは間違いなくあります。

しかし、私がこれをしなければならない場合、背景は本当に素晴らしいとは限りません。だから私は誰か他の人に絵を描かせるだろう。幸いなことに、Fill.Fillメソッドを使用すると、現在のアイテムの外観とコンポーネントの全体的な外観と互換性のある素敵な背景が生成されます。 `と` OnItemBkgDraw`イベントでのあなたの項目の変更を処理; =偽:

uses AdvGDIP; 

procedure TForm1.AdvSmoothListBox1ItemBkgDraw(Sender: TObject; Canvas: TCanvas; itemindex: Integer; itemRect: TRect; 
    var defaultdraw: Boolean); 
var 
    g: TGPGraphics; 
    ItemAppearance: TAdvSmoothListBoxItemAppearance; 
    ir: TGPRectF; 
begin 
// Disable default background drawing behavior 
DefaultDraw:= False; 

// Create our own item appearance which will be responsible for drawing the background 
// Note: The class needs an TAdvSmoothListBox owner, but we can't use ourselves as we would trigger an 
// infinite update cycle - use a dummy list instead (can be created dynamically or 
// just put it on your form being invisible) 
ItemAppearance:= TAdvSmoothListBoxItemAppearance.Create(DummyOwner); 
try 
    // Get the current item appearance which we want to adjust a little 
    ItemAppearance.Assign(AdvSmoothListBox1.ItemAppearance); 

    // Set nice colors for current item (you can use the itemindex parameter to see which item is currently being painted) 
    ItemAppearance.Fill.Color:= Random(High(TColor)); 
    ItemAppearance.Fill.ColorTo:= Random(High(TColor)); 

    // Now prepare the classes needed for drawing 
    g := TGPGraphics.Create(Canvas.Handle); 
    ir := MakeRect(itemrect.Left, itemrect.Top, itemrect.Right - itemrect.Left, itemrect.Bottom - itemrect.Top); 
    try 
    // And here it paints 
    ItemAppearance.Fill.Fill(g, ir); 
    finally 
    g.Free; 
    end; 
finally 
    ItemAppearance.Free; 
end; 
// Done 
end; 
+0

+1すてきな方法! – Simon

関連する問題