请教一个比较冷门的checkboxlist的问题

我真的是开开哥 2017-02-28 12:08:50
事情是这样的,用了一个checkboxlist控件,完了以后发现运行的时候每次选择除了选中小框以外,还会选中那一行,颜色会变蓝,请问怎么把这个变蓝的一行取消掉?我只想选择小框,不想选中整行,谢谢!或者怎么写能触发一个方法可以事后消除蓝色。
...全文
139 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
请大家帮帮忙,谢谢了
巴士上的邂逅 2017-02-28
  • 打赏
  • 举报
回复
可以来一个FlowLayoutPanel,往上面添加CheckBox,注意一下AutoSize属性
xdashewan 2017-02-28
  • 打赏
  • 举报
回复
自己继承一个,改写下事件

public class MyCheckedListBox : CheckedListBox
    {
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(new DrawItemEventArgs(e.Graphics, e.Font, new Rectangle(e.Bounds.Location, e.Bounds.Size), e.Index, (e.State & DrawItemState.Focus) == DrawItemState.Focus ? DrawItemState.Focus : DrawItemState.None, SystemColors.WindowText, this.BackColor));
        }
    }
浪子-无悔 2017-02-28
  • 打赏
  • 举报
回复
自定义一个checkbox用户控件 然后重写重写OnDrawItem 样式即可

    public partial class ColorCodedCheckedListBox  : CheckedListBox
    {
        public ColorCodedCheckedListBox()
        {
            InitializeComponent();
        }

        //重写OnDrawItem方法
        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 & DrawItemState.Focus) == DrawItemState.Focus ? DrawItemState.Focus : DrawItemState.None,
                Color.Orange, this.BackColor);
            base.OnDrawItem(e2);
        }
    }

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧