Add Menu and MenuItem in your code : MenuItem « GUI « VB.Net Tutorial

VB.Net Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statements
5. Date Time
6. Class Module
7. Development
8. Collections
9. Generics
10. Attributes
11. Event
12. Stream File
13. GUI
14. GUI Applications
15. 2D Graphics
16. I18N Internationlization
17. Reflection
18. Regular Expressions
19. Security
20. Socket Network
21. Thread
22. Windows
23. XML
24. Database ADO.net
25. Design Patterns
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial » GUI » MenuItem 
13. 18. 4. Add Menu and MenuItem in your code
Add Menu and MenuItem in your code
 

Imports System.IO

Imports System.Windows.Forms

public class MenuAddDynamically
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class


Public Class Form1
    Inherits System.Windows.Forms.Form
   Private ourMenu As MainMenu
   Private ourTop As MenuItem
   Private WithEvents ourItem As MenuItem

   Private Sub menuClick(ByVal sender As Object, ByVal e As System.EventArgs
      MessageBox.Show("You clicked " & sender.text & ".", _
      "Interactive Menu Creator!")
   End Sub



#Region " Windows Form Designer generated code "

   Public Sub New()
      MyBase.New()

      'This call is required by the Windows Form Designer.
      InitializeComponent()

      'Add any initialization after the InitializeComponent() call

   End Sub

   'Form overrides dispose to clean up the component list.
   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
         If Not (components Is NothingThen
            components.Dispose()
         End If
      End If
      MyBase.Dispose(disposing)
   End Sub
   Friend WithEvents btnMainMenu As System.Windows.Forms.Button
   Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox

   Friend WithEvents btnTopMnu As System.Windows.Forms.Button
   Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
   Friend WithEvents btnAddItem As System.Windows.Forms.Button
   Friend WithEvents lstTopLevel As System.Windows.Forms.ListBox
   Friend WithEvents Label5 As System.Windows.Forms.Label
   Friend WithEvents txtItemText As System.Windows.Forms.TextBox
   Friend WithEvents txtTopLevel As System.Windows.Forms.TextBox

   'Required by the Windows Form Designer
   Private components As System.ComponentModel.IContainer

   'NOTE: The following procedure is required by the Windows Form Designer
   'It can be modified using the Windows Form Designer.  
   'Do not modify it using the code editor.
   <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
      Me.btnMainMenu = New System.Windows.Forms.Button()
      Me.GroupBox1 = New System.Windows.Forms.GroupBox()
      Me.txtTopLevel = New System.Windows.Forms.TextBox()
      Me.btnTopMnu = New System.Windows.Forms.Button()
      Me.GroupBox2 = New System.Windows.Forms.GroupBox()
      Me.Label5 = New System.Windows.Forms.Label()
      Me.lstTopLevel = New System.Windows.Forms.ListBox()
      Me.btnAddItem = New System.Windows.Forms.Button()
      Me.txtItemText = New System.Windows.Forms.TextBox()
      Me.GroupBox1.SuspendLayout()
      Me.GroupBox2.SuspendLayout()
      Me.SuspendLayout()
      '
      'btnMainMenu
      '
      Me.btnMainMenu.Location = New System.Drawing.Point(4016)
      Me.btnMainMenu.Name = "btnMainMenu"
      Me.btnMainMenu.Size = New System.Drawing.Size(12840)
      Me.btnMainMenu.TabIndex = 0
      Me.btnMainMenu.Text = "Create the MainMenu"
      '
      'GroupBox1
      '
      Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtTopLevel, Me.btnTopMnu})
      Me.GroupBox1.Location = New System.Drawing.Point(4080)
      Me.GroupBox1.Name = "GroupBox1"
      Me.GroupBox1.Size = New System.Drawing.Size(344104)
      Me.GroupBox1.TabIndex = 1
      Me.GroupBox1.TabStop = False
      Me.GroupBox1.Text = "Add top-level Menu text:"
      '
      'txtTopLevel
      '
      Me.txtTopLevel.Location = New System.Drawing.Point(2424)
      Me.txtTopLevel.Name = "txtTopLevel"
      Me.txtTopLevel.Size = New System.Drawing.Size(27220)
      Me.txtTopLevel.TabIndex = 5
      Me.txtTopLevel.Text = ""
      '
      'btnTopMnu
      '
      Me.btnTopMnu.Location = New System.Drawing.Point(20064)
      Me.btnTopMnu.Name = "btnTopMnu"
      Me.btnTopMnu.Size = New System.Drawing.Size(8824)
      Me.btnTopMnu.TabIndex = 4
      Me.btnTopMnu.Text = "Make it so!"
      '
      'GroupBox2
      '
      Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label5, Me.lstTopLevel, Me.btnAddItem, Me.txtItemText})
      Me.GroupBox2.Location = New System.Drawing.Point(40216)
      Me.GroupBox2.Name = "GroupBox2"
      Me.GroupBox2.Size = New System.Drawing.Size(344248)
      Me.GroupBox2.TabIndex = 2
      Me.GroupBox2.TabStop = False
      Me.GroupBox2.Text = "Add menu item text:"
      '
      'Label5
      '
      Me.Label5.Location = New System.Drawing.Point(3264)
      Me.Label5.Name = "Label5"
      Me.Label5.Size = New System.Drawing.Size(25616)
      Me.Label5.TabIndex = 6
      Me.Label5.Text = "Select menu the item goes on:"
      '
      'lstTopLevel
      '
      Me.lstTopLevel.Location = New System.Drawing.Point(1688)
      Me.lstTopLevel.Name = "lstTopLevel"
      Me.lstTopLevel.Size = New System.Drawing.Size(288108)
      Me.lstTopLevel.TabIndex = 5
      '
      'btnAddItem
      '
      Me.btnAddItem.Location = New System.Drawing.Point(216208)
      Me.btnAddItem.Name = "btnAddItem"
      Me.btnAddItem.Size = New System.Drawing.Size(8824)
      Me.btnAddItem.TabIndex = 4
      Me.btnAddItem.Text = "Add Item!"
      '
      'txtItemText
      '
      Me.txtItemText.Location = New System.Drawing.Point(5632)
      Me.txtItemText.Name = "txtItemText"
      Me.txtItemText.Size = New System.Drawing.Size(20020)
      Me.txtItemText.TabIndex = 3
      Me.txtItemText.Text = ""
      '
      'Form1
      '
      Me.AutoScaleBaseSize = New System.Drawing.Size(513)
      Me.ClientSize = New System.Drawing.Size(440510)
      Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.GroupBox2, Me.GroupBox1, Me.btnMainMenu})
      Me.Name = "Form1"
      Me.Text = "Interactive menu creator"
      Me.GroupBox1.ResumeLayout(False)
      Me.GroupBox2.ResumeLayout(False)
      Me.ResumeLayout(False)

   End Sub

#End Region

   Private Sub btnMainMenu_Click(ByVal sender As System.Object, _
       ByVal e As System.EventArgsHandles btnMainMenu.Click
      ourMenu = New MainMenu()
      Me.Menu = ourMenu
   End Sub

   Private Sub btnTopMnu_Click(ByVal sender As System.Object, _
       ByVal e As System.EventArgsHandles btnTopMnu.Click
      Dim itemString As String = txtTopLevel.Text
      ourTop = New MenuItem(itemString)
      ourMenu.MenuItems.Add(ourTop)
      lstTopLevel.Items.Add(itemString)
   End Sub

   Private Sub btnAddItem_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgsHandles btnAddItem.Click
      Dim As Integer
      i = 0
      ourItem = New MenuItem(txtItemText.Text, New System.EventHandler (AddressOf Me.menuClick))
      ourMenu.MenuItems(i).MenuItems.Add(ourItem)

   End Sub
End Class

        
13. 18. MenuItem
13. 18. 1. Add submenu to menuAdd submenu to menu
13. 18. 2. Set MenuItem visible and invisibleSet MenuItem visible and invisible
13. 18. 3. Set MenuItem to RadioCheck/CheckedSet MenuItem to RadioCheck/Checked
13. 18. 4. Add Menu and MenuItem in your codeAdd Menu and MenuItem in your code
13. 18. 5. Owner Draw MenuItemOwner Draw MenuItem
w__ww_._j__a_v__a_2_s._co_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.