dotnet/winforms

CheckListBox has Bugs

Open

#3892 aperta il 13 set 2020

Vedi su GitHub
 (12 commenti) (0 reazioni) (0 assegnatari)C# (922 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (4100 star)
Metriche merge PR
 (Merge medio 14g 22h) (56 PR mergiate in 30 g)

Descrizione

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

`

Guida contributor