Create Menu in your code : Menu « GUI « VB.Net Tutorial






Create Menu in your code
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








14.17.Menu
14.17.1.Create Menu in your codeCreate Menu in your code
14.17.2.Add Menu to Form window and attach actionsAdd Menu to Form window and attach actions
14.17.3.Build menu at runtimeBuild menu at runtime
14.17.4.Using menus to change font colors and stylesUsing menus to change font colors and styles
14.17.5.Owner draw menuOwner draw menu