protected override void OnMouseDown(MouseEventArgs e)
{
Point pos = new Point(e.X, e.Y);
for(int i=0; i<_drawCommands.Count; i++)
{
DrawCommand dc = _drawCommands[i] as DrawCommand;
// Find the DrawCommand this is over
if (dc.DrawRect.Contains(pos))
{
// Is an item already selected?
if (_selected)
{
// Is it this item that is already selected?
if (_trackItem == i)
{
// Is a popupMenu showing
if (_popupMenu != null)
{
// Dismiss the submenu
_popupMenu.Dismiss();
// No reference needed
_popupMenu = null;
}
}
}
else
{
// Select the tracked item
_selected = true;
_drawUpwards = false;
GrabTheFocus();
// Is there a change in tracking?
if (_trackItem != i)
{
// Modify the display of the two items
_trackItem = SwitchTrackingItem(_trackItem, i);
}
else
{
// Update display to show as selected
DrawCommand(_trackItem, true);
}
// Is there a submenu to show?
if (dc.Chevron || (dc.MenuCommand.MenuCommands.Count > 0))
WindowsAPI.PostMessage(this.Handle, WM_OPERATEMENU, 1, 0);
}
break;
}
}
base.OnMouseDown(e);
}