/// <summary> /// Handles the MouseMove event of the FittingContentListBox control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param> private void FittingContentListBox_MouseMove(object sender, MouseEventArgs e) { for (int i = 0; i < FittingContentListBox.Items.Count; i++) { // Skip until we found the mouse location Rectangle rect = FittingContentListBox.GetItemRectangle(i); if (!rect.Contains(e.Location)) { continue; } Object item = FittingContentListBox.Items[i]; FittingContentListBox.Cursor = item is KillLogItem ? CustomCursors.ContextMenu : Cursors.Default; return; } // If we went so far, we're not over anything FittingContentListBox.Cursor = Cursors.Default; }
/// <summary> /// Handles the MouseDown event of the FittingContentListBox control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param> private void FittingContentListBox_MouseDown(object sender, MouseEventArgs e) { // Retrieve the item at the given point and quit if none int index = FittingContentListBox.IndexFromPoint(e.Location); if (index < 0 || index >= FittingContentListBox.Items.Count) { return; } KillLogItem killLogItem = FittingContentListBox.Items[index] as KillLogItem; // Beware, this last index may actually means a click in the whitespace at the bottom // Let's deal with this special case if (index == FittingContentListBox.Items.Count - 1) { Rectangle itemRect = FittingContentListBox.GetItemRectangle(index); if (!itemRect.Contains(e.Location)) { killLogItem = null; } } if (e.Button != MouseButtons.Right) { return; } // Right click reset the cursor FittingContentListBox.Cursor = Cursors.Default; // Set the selected item m_selectedItem = killLogItem?.Item; // Display the context menu contextMenuStrip.Show(FittingContentListBox, e.Location); }