Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - Focusing on Forms and Menus in Visual Basi...
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Focusing on Forms and Menus in Visual Basic
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2007-03-01

    Table of Contents:
  • Focusing on Forms and Menus in Visual Basic
  • 4.16 Creating a Fading Form
  • 4.17 Creating a Nonrectangular Form
  • 4.18 Changing Menus at Runtime
  • 4.19 Creating Shortcut Menus

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Focusing on Forms and Menus in Visual Basic - 4.19 Creating Shortcut Menus
    (Page 5 of 5 )

    Problem

    You want to display a custom shortcut menu to users when they right-click on a form or one of its controls.

    Solution

    Sample code folder: Chapter 04\ShortcutMenus 

    Use theContextMenuStrip control to design a shortcut menu (also called a context or pop-up menu) that you can attach to the controls (or form) of your choice.

    Create a new Windows Forms application, and add aContextMenuStripcontrol namedMainShortcutMenu to the form. When you select that control, it adds a temporary standard menu to the control that you can use to add new menu items (see Figure 4-20).


    Figure 4-20.  Shortcut menus in design mode

    Add two menu items to this shortcut menu:

    • A menu item namedMenuHello, usingSay Hellofor itsText property
    • A menu item namedMenuGoodbye, usingSay Goodbyefor itsTextproperty

    Select the form itself, and then change itsContextMenuStripproperty toMainShortcutMenu.

    Now, add the following source code to the form’s code template:

      Private Sub MenuHello_Click(ByVal sender As System.Object,_
            ByVal e As System.EventArgs) Handles MenuHello.Click
         MsgBox("Hello")
      End Sub

      Private Sub MenuGoodbye_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles MenuGoodbye.Click
         MsgBox("Goodbye")
      End Sub

    Run the program, and right-click on the form. The shortcut menu will present itself, as shown in Figure 4-21. Clicking on the items puts up a message box saying “Hello” or “Goodbye.”


    Figure 4-21.  The shortcut menu in use

    Discussion

    Each form and control includes a ContextMenuStrip property that you can assign to any ContextMenuStrip control included with your form. You can create as many shortcut menus as needed for your controls.

    Some controls, such as theTextBoxcontrol, already include default shortcut menus. If you wish to enhance one of these menus, you will have to design your own menu from scratch and provide your own implementations for menu items previously found in that control’s shortcut menu.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Visual Basic 2005 Cookbook," published by...
     

    Buy this book now. This article is excerpted from chapter four of the Visual Basic 2005 Cookbook, written by Tim Patrick and John Clark Craig (O'Reilly; ISBN: 0596101775). Check it out today at your favorite bookstore. Buy this book now.

    VISUAL BASIC.NET ARTICLES

    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway