/// <summary> /// Invoked when the ComboBox has to render the drop-down items. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void CheckComboBox_DrawItem(object sender, DrawItemEventArgs e) { // make sure the index is valid (sanity check) if (e.Index == -1) { return; } // test the item to see if its a MCheckComboBoxItem if (!(Items[e.Index] is MCheckComboBoxItem)) { // it's not, so just render it as a default string e.Graphics.DrawString( Items[e.Index].ToString(), this.Font, Brushes.Black, new Point(e.Bounds.X, e.Bounds.Y)); return; } // get the MCheckComboBoxItem from the collection MCheckComboBoxItem box = (MCheckComboBoxItem)Items[e.Index]; // render it CheckBoxRenderer.RenderMatchingApplicationState = true; CheckBoxRenderer.DrawCheckBox( e.Graphics, new Point(e.Bounds.X, e.Bounds.Y), e.Bounds, box.Text, this.Font, (e.State & DrawItemState.Focus) == 0, box.CheckState ? CheckBoxState.CheckedNormal : CheckBoxState.UncheckedNormal); }
/// <summary> /// Invoked when the selected index is changed on the dropdown. This sets the check state /// of the MCheckComboBoxItem and fires the public event CheckStateChanged using the /// MCheckComboBoxItem as the event sender. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void CheckComboBox_SelectedIndexChanged(object sender, EventArgs e) { MCheckComboBoxItem item = (MCheckComboBoxItem)SelectedItem; item.CheckState = !item.CheckState; this.DroppedDown = true; //if (CheckStateChanged != null) // CheckStateChanged(item, e); }