/// <summary> /// Processes the flags on check state changed. Include this method in the event handler for ItemCheckStateChanged. /// </summary> /// <param name="item">The item that was changed.</param> public void ProcessFlagsOnCheckStateChanged <T>(CheckBoxListItem item) where T : struct, IConvertible { IsValidEnum <T>(); if (item == null) { throw new ArgumentNullException(nameof(item)); } bool set = item.Checked; T newVal = GetFlagsValue <T>(Activator.CreateInstance <T>()); for (int i = 0; i < items.Count; i++) { CheckBoxListItem curItem = items[i]; bool changed = false; if (set && (EnumHasValue <T>(newVal, curItem.Tag) || EnumHasValue <T>(curItem.Tag, item.Tag)) && !curItem.Checked) { curItem.Checked = true; changed = true; } if (!set && EnumHasValue <T>(curItem.Tag, item.Tag) && curItem.Checked) { curItem.Checked = false; changed = true; } if (changed) { InvalidateItem(i); } } }
/// <summary> /// Paints the button. /// </summary> /// <param name="g">A <see cref="Graphics" /> reference.</param> /// <param name="index">The index of the item.</param> /// <param name="bounds">The bounds in which to paint the item.</param> protected override void PaintButton(Graphics g, int index, Rectangle bounds) { CheckBoxListItem li = BaseItems[index] as CheckBoxListItem; // Get current state CheckBoxState curState = (CheckBoxState)(((int)li.CheckState * 4) + 1); if (!Enabled || !li.Enabled) { curState += 3; } else if (index == PressingItem) { curState += 2; } else if (index == HoverItem) { curState++; } // Draw glyph Microsoft.Win32.NativeMethods.BufferedPaint.Paint <CheckBoxState, CheckBoxListItem>(g, this, bounds, PaintAnimatedButton, lastState, curState, GetTransition(curState, lastState), li); lastState = curState; }
/// <summary> /// Determines whether the specified <see cref="CheckBoxListItem"/> is equal to the current <see cref="CheckBoxListItem"/>. /// </summary> /// <param name="other">The <see cref="CheckBoxListItem"/> to compare with the current <see cref="CheckBoxListItem"/>.</param> /// <returns> /// true if the specified <see cref="CheckBoxListItem"/> is equal to the current <see cref="CheckBoxListItem"/>; otherwise, false. /// </returns> public bool Equals(CheckBoxListItem other) => base.Equals((ButtonListItem)other) && CheckState == other.CheckState;
/// <summary> /// Initializes a new instance of the <see cref="CheckBoxListItemCheckStateChangedEventArgs" /> class. /// </summary> /// <param name="item">The item.</param> /// <param name="index">The index.</param> public CheckBoxListItemCheckStateChangedEventArgs(CheckBoxListItem item, int index) { Item = item; ItemIndex = index; }
private void PaintAnimatedButton(Graphics g, Rectangle bounds, CheckBoxState curState, CheckBoxListItem li) { Point gp = li.GlyphPosition; gp.Offset(bounds.Location); CheckBoxRenderer.DrawCheckBox(g, gp, curState); }