首页WIN11问题C# checkedListBox控件选项被选中后,背景色可否不变

C# checkedListBox控件选项被选中后,背景色可否不变

时间2022-12-12 20:30:35发布分享专员分类WIN11问题浏览87

为了你这个问题想了很多,没有分真是浪费时间了checkedlistbox 。好了,好人做到底,我给你我忙了后的代码,其实就是重写OnDrawItem而已。

这个是FORM1,其中Form1.Designer.cs为空代码checkedlistbox 。下图演示就是选中时为背景为透明色

C# checkedListBox控件选项被选中后,背景色可否不变

using Sys来自tem;

using System.Collections.Generic;

using System.ComponentModel;

using ***.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

n360问答amespace WindowsFormsApplicat化业ion2

    public partial class Form1 : Form

        public Form1()

            InitializeComponent();

        private System.ComponentModel.IContainer components = null;

        private ColorCodedCheckedListBox checkedListBox1;

        protected override void Dispose(bool disposing)

            if (disposing && (components !陈且续= null))

                c乙是存四径慢顶omponents.Dispose();

            b差息封盾四曾低段ase.Dispose(disposing);

        private void InitializeComponent()

            this.checkedListBox1 = new WindowsFormsApplication2.ColorCodedCheckedListBox();

            this.SuspendLayout();

            this.checkedListBox1.FormattingEnabled = true;

            t探每绍房剧his.checke圆远应省错dListBox1.Items.AddRange(new obj团代满款ect[] {"选项1","选项2"});

            this.checkedListBox1.Location = new System.Drawing.Point(12, 12);

            t宪妒论范均严征必判外措his.***.Name = "checkedListBox1";

            t石裂checkedlistbox 我剂为消鲁训感古his.checkedListBox1.Size = new System.Drawing.Size(128, 36);

            this.checkedListBox1.TabIndex = 0;

            this.AutoScaleDimensions = new Syste铁乐弦m.Drawing.SizeF(6F, 1角当某日飞构套2F);

            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

            this.ClientS黑院ize = new S战编减ystem.Drawing.Size(164, 67);

            t红his.Controls.Add(this.checkedListBox1);

            ***.Name = "Form1";

            this.Text = "Form1";

            this.ResumeLayout(false);

    class ColorCodedCheckedListBox : CheckedListBox

        //***.Ora些际随三圆顺请行吸革nge为颜色checkedlistbox ,你可修改

        protected override void OnD工政太论吸农引与rawItem(DrawItemEventArgs e)

            DrawItemEventArgs e2 = new DrawItemEventArgs(剂元收于***.Graphics, e.Font, new Rectangle(e.Bounds.Location, e.Bounds.Size), e.Index, (e.State & DrawItemState.Focus) == DrawItemState.Focus ? DrawItemState.Focus : DrawItemState.None, ***.Orange, this.BackColor);

            base.OnDrawItem(e2);

爱资源吧版权声明:以上文中内容来自网络,如有侵权请联系删除,谢谢。

C#checkedListBox项被选C#项被选checkedlistbox
Linux上查看DNS服务器及设置DNS服务器 求用c#编一个程序把CheckedListBox上选到的选项的内容输出到一个label上来自