Use the contextmenustrip control/beginner

Source: Internet
Author: User
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.*/


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.