dotnet/winforms

CheckListBox has Bugs

Open

#3,892 创建于 2020年9月13日

在 GitHub 查看
 (12 评论) (0 反应) (0 负责人)C# (922 fork)batch import
enhancementhelp wanted

仓库指标

Star
 (4,100 star)
PR 合并指标
 (平均合并 14天 22小时) (30 天内合并 56 个 PR)

描述

  • .NET Core Version: This is a problem with the. Net framework and does not test the. Net core
  • Have you experienced this same bug with .NET Framework?: Yes

Problem description: This is a bug from CheckListBox. When I derive a new CheckListBox from CheckListBox, using my derived MyCheckListBox, it will be very slow to change the itemcheckstate when the item is not selected. It will be very fast to change the itemcheckstate after selecting the item.

Expected behavior: The rate at which itemcheckstate changes is independent of the itemselect state

Minimal repro: every time

Code: `

using System;
using System.Windows.Forms;
namespace Test.Frm.Control
{
    internal class MyCheckListBox : CheckedListBox
    {
        public delegate void ItemBoxCheckedEventHanlder(object sender, Models.CheckListBoxItemCheckBoxEventArgs mouseEventArgs);
        public event ItemBoxCheckedEventHanlder ItemBoxChecked;
        private bool isUserCheck = false;
        public MyCheckListBox()
        {
            this.DoubleBuffered = false;
        }
        protected override void OnItemCheck(ItemCheckEventArgs ice)
        {
            if (this.isUserCheck)
            {
                this.isUserCheck = false;
                ice.NewValue = ice.CurrentValue;
            }
            base.OnItemCheck(ice);
        }
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x0201)///LeftMouseButtonDown
            {
                uint lPararm = (uint)m.LParam;
                int xPoint = Convert.ToInt32(lPararm & 0xFFFF);///Convert mouse X coordinates
                int yPoint = Convert.ToInt32(lPararm >> 16);///Convert mouse Y coordinates
                int index = this.IndexFromPoint(xPoint, yPoint);
                if (xPoint < 15)
                {
                    Models.CheckListBoxItemCheckBoxEventArgs model = new Models.CheckListBoxItemCheckBoxEventArgs(MouseButtons.Left, xPoint, yPoint, index);
                    base.SetItemCheckState(index, base.GetItemCheckState(index) == CheckState.Unchecked ? CheckState.Checked : CheckState.Unchecked);
                    this.ItemBoxChecked?.Invoke(this, model);
                }
                else
                {
                    this.isUserCheck = true;
                    base.SelectedIndex = index;
                }
            }
            else
            {
                base.WndProc(ref m);
            }
        }
    }
}

`

贡献者指南