如何以不同的颜色绘制选定的列表框项目? [英] How do I draw the selected list-box item in a different color?

查看:30
本文介绍了如何以不同的颜色绘制选定的列表框项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改 TListBox 中的项目选择焦点颜色和文本颜色?

Is is possible to change the item selection focus color and text color in a TListBox?

当项目中没有启用主题,或者列表框样式设置为自绘时,项目周围的选择被涂成蓝色,我相信这是由系统的外观设置全局定义的.

When themes are not enabled in the project, or the list box style is set to owner-draw, the selection around the item is painted blue, which I believe is globally defined by the system's appearance settings.

我想将所选项目的颜色更改为自定义颜色.

I would like to change the color of selected items to a custom color.

举个例子,结果是这样的:

So an example, the result would be something like this:

注意最后一个列表框已在 Paint 中修改以说明示例.

Note the last listbox has been modified in Paint to illustrate the example.

推荐答案

试试这个:

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
begin
  with (Control as TListBox).Canvas do
  begin
    if odSelected in State then
      Brush.Color := $00FFD2A6;

    FillRect(Rect);
    TextOut(Rect.Left, Rect.Top, (Control as TListBox).Items[Index]);
    if odFocused In State then begin
      Brush.Color := ListBox1.Color;
      DrawFocusRect(Rect);
    end;
  end;
end;

这篇关于如何以不同的颜色绘制选定的列表框项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆