自定义 TAdvSmoothListBox 项目颜色

发布于 2024-11-29 14:58:46 字数 248 浏览 0 评论 0原文

我刚刚安装了 Delphi 的 TMS 组件,在 TAdvSmoothListBox 中我想自定义颜色每个项目。

我实际上正在使用 .ItemAppearance.Fill.Color 但它用相同的颜色填充所有项目。

谁能建议我如何单独设置每个项目的颜色?

谢谢

I've just installed TMS Components for Delphi and in TAdvSmoothListBox I would like to customize colors for each item.

I am actually using the .ItemAppearance.Fill.Color but it fills all the items with the same color.

Can anyone suggest me how to set the colors for each item separately ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心在旅行 2024-12-06 14:58:46

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;

The event OnItemBkgDraw is definitely what you need to draw the background yourself.

But if I had to do this the background would never look really nice. So I would let somebody else do the drawing. Fortunately we can use the Fill.Fill method which will generate a nice background which is compatible with the current item appearance and the overall look of the component.

This is your OnItemBkgDraw handler:

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;
若水微香 2024-12-06 14:58:46

我认为 Daemon_x 就在这里,我认为默认情况下您不能使用 TAdvSmoothlistbox 的属性/方法来执行此操作。

您可以轻松更改字体、图像等,但背景颜色需要使用 OnItemBkgDraw 和/或 OnItemDraw 事件来完成。

(截至版本 2.4.0.1)

I think Daemon_x is right here, i dont think you can do this with the properties/methods of the TAdvSmoothlistbox by default.

You can easily change fonts, images etc, but the background color needs to be done using the OnItemBkgDraw and/or the OnItemDraw events.

(as at version 2.4.0.1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文