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

`

貢獻者指南