ms改变的SelectedItem的颜色的CheckedList

ms改变的SelectedItem的颜色的CheckedList

本文介绍了如何在WindowsForms改变的SelectedItem的颜色的CheckedListBox?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变那些chedked中的CheckedListBox在C#WindowsForms项目的颜色。

I want to change the color of the items that are chedked in the CheckedListBox in C# WindowsForms.

任何一个可以帮助我解决这个问题!

Can any one help me to solve this problem!

推荐答案

这应该让你开始。我一个子类的CheckedListBox 和覆盖绘图事件。结果所有选中的列表中的项目与一个红色背景画。

This should get you started. I've subclassed a CheckedListBox and overridden the drawing event. The result is all checked items in the list are drawn with a red background.

从这个玩弄,如果你想复选框后面的区域,以不同的颜色还有,使用 e.Graphics.FillRectangle 之前调用 base.OnDrawItem

From playing around with this, if you want the area behind the checkbox to be a different colour as well, use e.Graphics.FillRectangle before calling base.OnDrawItem.

class ColouredCheckedListBox : CheckedListBox
{
    protected override void OnDrawItem(DrawItemEventArgs e)
    {
        DrawItemEventArgs e2 =
            new DrawItemEventArgs
            (
                e.Graphics,
                e.Font,
                new Rectangle(e.Bounds.Location, e.Bounds.Size),
                e.Index,
                e.State,
                e.ForeColor,
                this.CheckedIndices.Contains(e.Index) ? Color.Red : SystemColors.Window
            );

        base.OnDrawItem(e2);
    }
}

这篇关于如何在WindowsForms改变的SelectedItem的颜色的CheckedListBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:23