小编Bas*_*tiz的帖子

如何更改ListView的默认选择颜色?

我正在尝试更改 ListView 中选择栏的默认(蓝色)颜色。
我拒绝使用 ObjectListView 因为我必须更改所有代码。

我搜索过这个主题,并在这里找到了一些答案:
更改 ListView 的背景选择颜色?
但它指向 ObjectListView。

当我之前使用 ListBox 时,这可以根据我的喜好设置选择栏颜色:

  1. OwnerDrawFixed在“属性”下 将“绘制模式”设置为
  2. 将 DrawItem 设置为ListBox1_DrawItemEvents 下

private void ListBox1_DrawItem(object sender, DrawItemEventArgs e)
{
    if (e.Index < 0) return;
    //if the item state is selected them change the back color 
    if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
        e = new DrawItemEventArgs(e.Graphics,
                                  e.Font,
                                  e.Bounds,
                                  e.Index,
                                  e.State ^ DrawItemState.Selected,
                                  e.ForeColor,
                                  Color.FromArgb(43, 144, 188));//Choose the color

    // Draw the background of the ListBox control for each item. …
Run Code Online (Sandbox Code Playgroud)

.net c# listview selection winforms

4
推荐指数
1
解决办法
2844
查看次数

标签 统计

.net ×1

c# ×1

listview ×1

selection ×1

winforms ×1