views:

390

answers:

0

I have attached a ContextMenuStrip to a TabControl and set up a handler for OnMouseDown that does the following:

  if (e.Button != MouseButtons.Right) {
    return;
  }

  for (var i = 0; i < tabControl1.TabCount; ++i) {
    var point = new Point(e.X, e.Y);

    if (tabControl1.GetTabRect(i).Contains(point)) {
      tabPageContextMenu.Show(tabControl1, point);
    }
  }

This properly shows the ContextMenuStrip however, inside the Click event for the MenuItem contained by the ContextMenuStrip I cannot seem to access the underlying TabControl or TabPage that actually spawned the ContextMenuStrip.

The questions then becomes this: How can I best access the originating control? Obviously in the MouseDown handler I could assign the control to a private class variable but I assumed there was a standard way via some property that I am currently overlooking.

Thanks in advance!