1

TMS Components for Delphi をインストールしたばかりで、TAdvSmoothListBoxで各項目の色をカスタマイズしたいと考えています。

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

各アイテムの色を個別に設定する方法を誰かに教えてもらえますか?

ありがとう

4

2 に答える 2

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;
于 2011-08-12T15:18:11.613 に答える
1

Daemon_x はここにあると思いますが、デフォルトで TAdvSmoothlistbox のプロパティ/メソッドを使用してこれを行うことはできないと思います。

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

(バージョン 2.4.0.1 の場合)

于 2011-08-12T11:23:00.607 に答える