public void setup() { int h = listBox.GetItemHeight(0); var sz = panel.Size; int btnCount = sz.Height / h; if (null != buttons) { foreach (var b in buttons) { b.Dispose(); } } buttons = new MnemonicLabel[btnCount]; for (int i = 0; i < btnCount; i++) { int ii = i; buttons[i] = new MnemonicLabel(() => { if (listBox.Items.Count > ii) { listBox.SetItemChecked(ii, true); } }); panel.Controls.Add(buttons[i]); buttons[i].Size = new System.Drawing.Size(h - 1, h - 1); var lbFont = listBox.Font; System.Drawing.Font f = new System.Drawing.Font(lbFont.FontFamily, lbFont.Height * 2 / 3); buttons[i].Font = f; buttons[i].Location = new System.Drawing.Point(0, h * i); buttons[i].Text = String.Format("&{0}", i + 1); buttons[i].Margin = new System.Windows.Forms.Padding(0); buttons[i].FlatStyle = System.Windows.Forms.FlatStyle.Flat; buttons[i].UseMnemonic = true; buttons[i].TabStop = true; buttons[i].TabIndex = 1 + i; buttons[i].TextAlign = System.Drawing.ContentAlignment.MiddleCenter; buttons[i].Visible = false; } listBox.TabIndex = btnCount + 1; listBox.Size = new System.Drawing.Size(sz.Width - h, sz.Height); }
/// <summary> /// Event Handler from the checked list box ItemCheck Event. /// Enabled/disable the real time stylus plugin corresponding /// to the item being checked/unchecked. /// </summary> /// <param name="sender">The control that raised the event.</param> /// <param name="e">The event arguments.</param> private void chklbPlugins_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) { // The CheckedListBox CheckOnClick property allows the user // to toggle the checkbox without first selecting the list item, // but since the list also allows the user to rearrange the // items, we only want CheckOnClick to proceed if the user clicks // on the checkbox itself. if (lastMouseDownEventArgs != null) { // If we previously cached MouseDownEventArgs, check the MouseDown location. bool abortItemCheck = (lastMouseDownEventArgs.X > chklbPlugins.GetItemHeight(e.Index)); // Reset the cache lastMouseDownEventArgs = null; // If the MouseDown location is outside the checkbox area, abort. if (abortItemCheck) { e.NewValue = e.CurrentValue; return; } } // Enable/disable the plugin according to its new // checked value. A plugin is enabled by inserting // it into the real time stylus notification chain and it is // disabled by removing it from the plugin collection. The dynamic // renderer is handled specially by setting its enabled // property. if (e.Index < chklbPlugins.Items.Count) { if (e.NewValue == CheckState.Checked) { InsertIntoPluginCollection(e.Index); } else if (e.NewValue == CheckState.Unchecked) { RemoveFromPluginCollection(e.Index); } } // Clear the form Clear(); }