Attaching mouse click event to specific controls or you can write something to attach to all controls by iteration through the form's Controls collection.
label1.MouseClick += new MouseEventHandler(control_RightMouseClick);
gridview1.MouseClick += new MouseEventHandler(control_RightMouseClick);
Then perform different operations or show different context menu for different controls
if (e.Button != MouseButtons.Right)
{
return;
}
if (sender.GetType().IsSubclassOf(typeof(Control)))
{
Control formControl = (Control)sender;
switch (formControl.Name)
{
case "label1":
contextMenuStrip1.Show(formControl, e.Location);
break;
case "gridview1":
contextMenuStrip2.Show(formControl, e.Location);
break;
default:
contextMenuStrip_default.Show(formControl, e.Location);
break;
}
}
return;