ContextmenustripControls:
Shortcut menus are displayed when you right-click a widget or a specific area in the form. Shortcut menus are usually used to combine different menu items of a menustrip from a form, so that you can easilyProgramIn the context.
Problem:Add a tabcontrol to a form to display multiple Content in the same format, add "close", "close all", and "save" operations on each tabpage of tabcontrol;
Solution:Add a contextmenustrip control to the form and edit its menu items. When you right-click a tabpage, The contextmenustrip shortcut menu appears and select the corresponding operation;
1. Right-click the selected tabpage:/mouse_down event.
Code
Private Void Tabcontrol1_mousedown ( Object Sender, mouseeventargs E)
{
If (E. Button = Mousebuttons. Right)
{
For ( Int I = 0 ; I < Tabcontrol1.tabpages. Count; I ++ )
{
Tabpage TP = Tabcontrol1.tabpages [I];
If (Tabcontrol1.gettabrect (I). Contains ( New Point (E. X, E. y )))
{
Tabcontrol1.selectedtab = TP;
}
}
}
}
2. Set the menu display position
Tabcontrol1.selectedtab. contextmenustrip= This. Contextmenustrip1;
This. Contextmenustripclose. Show (mouseposition );
/*(E. X, E. y) The displayed coordinates are the relative coordinates in the current control, not the screen coordinates.*/