ContextMenuStrip in Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This lesson describes the ContextMenuStrip control


This component represents a context menu and when you select it on the form at design time, your IDE displays the menu at the top of the form.

design view

Once you have it added to the form, enter the menu's items (use the Properties window to set their names and other properties), and then double-click them to edit their event handlers.

adding items


    Private Sub NewStudentItem_Click(sender As Object, e As EventArgs) _
     Handles NewStudentItem.Click
        ' The AddStudent is a Form for adding a new student
        Dim newstudent As Form = AddStudent
        newstudent.ShowDialog() ' display AddStudent as a modal dialog
    End Sub

To use a ContextMenuStrip, you should attach it to a control or form (use the Properties window to set ContextMenuStrip property to your ContextMenuStrip component). The rest is automatic. When the user right-clicks this control or form at runtime, Visual Basic automatically displays the ContextMenuStrip. If the user selects one of the menu's items, Visual Basic triggers the menu item's event handler.


Previous Lesson | Next Lesson

Share This

Home | About | Contact | Privacy Policy

Copyright 2018 - All Rights Reserved.