Highlighted color not getting overriden by OnDrawItem WindowsForms c#

29 Views Asked by At
protected override void OnDrawItem(DrawItemEventArgs e)
    {
        e.DrawBackground();
        //This would have to feel the ractangle, it does so, but default (blue) highlight color is still there
        if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
        {
            using (Brush brush = new SolidBrush(Color.FromArgb(40, 40, 40)))
            {
                e.Graphics.FillRectangle(brush, e.Bounds);
            }
            e.DrawFocusRectangle();
        }

        //SystemColors.Highlight = Color.Gray;

        this.CheckOnClick = true;
        DrawItemEventArgs e2 =
        new DrawItemEventArgs
        (
            e.Graphics,
            e.Font,
            new Rectangle(e.Bounds.Location, e.Bounds.Size),
            e.Index,
            e.State & ~DrawItemState.Selected, 
            e.ForeColor,
            e.BackColor
        );  
        

        base.OnDrawItem(e2);
    }

This code is for overriding CustomCheckedListbox settings so the highlighted color would either dissapear or be different color. It does fill the ractangle but only the Checkbox part.

My question is how would I disable affect of highlighting, or make it to just override the highlight color?

0

There are 0 best solutions below