dotnet/winforms

CheckListBox has Bugs

Open

#3,892 opened on 2020年9月13日

GitHub で見る
 (12 comments) (0 reactions) (0 assignees)C# (922 forks)batch import
enhancementhelp wanted

Repository metrics

Stars
 (4,100 stars)
PR merge metrics
 (平均マージ 14d 22h) (30d で 56 merged PRs)

説明

  • .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);
            }
        }
    }
}

`

コントリビューターガイド