Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class MenuCreationInCode
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Inherits System.Windows.Forms.Form
Dim mainMenu1 As New MainMenu
Dim WithEvents menuItem1 As New MenuItem
Dim WithEvents menuItem2 As New MenuItem
Dim WithEvents menuItem3 As New MenuItem
Dim WithEvents menuItem4 As New MenuItem
Public Sub New()
MyBase.New()
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
menuItem1.Text = "File"
menuItem2.Text = "Item 1"
menuItem3.Text = "Item 2"
menuItem3.Checked = True
menuItem4.Text = "Exit"
menuItem4.Shortcut = Shortcut.CtrlX
menuItem2.MenuItems.Add(menuItem3)
menuItem1.MenuItems.Add(menuItem2)
menuItem1.MenuItems.Add(menuItem4)
AddHandler menuItem4.Click, AddressOf MenuItem4_Click
mainMenu1.MenuItems.Add(menuItem1)
Menu = mainMenu1
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs)
Console.WriteLine("action")
End Sub
End Class