Owner draw Menu with selection highlight : Menu « GUI « VB.Net

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
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
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VB.Net » GUI » MenuScreenshots 
Owner draw Menu with selection highlight
Owner draw Menu with selection highlight

Imports System
Imports System.Drawing
Imports System.Windows.Forms


Public Class MainClass
    
    Shared Sub Main()
        Dim form1 As Form = New Form1

        Application.Run(form1)


    End Sub
End Class

Public Class Form1
    Inherits System.Windows.Forms.Form

#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

    '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.
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents mnuFile As System.Windows.Forms.MenuItem
    Friend WithEvents mnuNew As System.Windows.Forms.MenuItem
    Friend WithEvents mnuOpen As System.Windows.Forms.MenuItem
    Friend WithEvents mnuSave As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.MainMenu1 = New System.Windows.Forms.MainMenu()
        Me.mnuFile = New System.Windows.Forms.MenuItem()
        Me.mnuNew = New System.Windows.Forms.MenuItem()
        Me.mnuOpen = New System.Windows.Forms.MenuItem()
        Me.mnuSave = New System.Windows.Forms.MenuItem()
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile})
        '
        'mnuFile
        '
        Me.mnuFile.Index = 0
        Me.mnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuNew, Me.mnuOpen, Me.mnuSave})
        Me.mnuFile.Text = "File"
        '
        'mnuNew
        '
        Me.mnuNew.Index = 0
        Me.mnuNew.OwnerDraw = True
        Me.mnuNew.Text = "New"
        '
        'mnuOpen
        '
        Me.mnuOpen.Index = 1
        Me.mnuOpen.OwnerDraw = True
        Me.mnuOpen.Text = "Open"
        '
        'mnuSave
        '
        Me.mnuSave.Index = 2
        Me.mnuSave.OwnerDraw = True
        Me.mnuSave.Text = "Save"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(514)
        Me.ClientSize = New System.Drawing.Size(292266)
        Me.Font = New System.Drawing.Font("Tahoma"8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Menu = Me.MainMenu1
        Me.Name = "Form1"
        Me.Text = "Owner-Drawn Menu"

    End Sub

#End Region

    Private Sub mnu_MeasureItem(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MeasureItemEventArgsHandles mnuNew.MeasureItem, mnuOpen.MeasureItem, mnuSave.MeasureItem
        Dim mnuItem As MenuItem = CType(sender, MenuItem)
        Dim MenuFont As New Font("Tahoma"8)
        e.ItemHeight = e.Graphics.MeasureString(mnuItem.Text, MenuFont).Height + 5
        e.ItemWidth = e.Graphics.MeasureString(mnuItem.Text, MenuFont).Width + 30
    End Sub

    Dim MenuImage As Image = New Bitmap("figure2.bmp")

    Private Sub mnu_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgsHandles mnuNew.DrawItem, mnuOpen.DrawItem, mnuSave.DrawItem
        Dim mnuItem As MenuItem = CType(sender, MenuItem)

        If e.State And DrawItemState.Selected = DrawItemState.Selected Then
            e.DrawBackground()
        End If
        e.Graphics.DrawImage(MenuImage, e.Bounds.Left + 3, e.Bounds.Top + 2)
        e.Graphics.DrawString(mnuItem.Text, e.Font, New SolidBrush(e.ForeColor), e.Bounds.Left + 25, e.Bounds.Top + 3)
    End Sub
End Class

           
       
Related examples in the same category
1. Create Menu at run timeCreate Menu at run time
2. Get Menu StructureGet Menu Structure
3. Owner Draw MenuItemOwner Draw MenuItem
4. Add Menu, Menu Item and bind action at run timeAdd Menu, Menu Item and bind action at run time
5. Menu action DemoMenu action Demo
6. Menu Item and Menu ActionMenu Item and Menu Action
7. Using menus to change font colors and stylesUsing menus to change font colors and styles
8. Add menu to a frame and implement the menu actionAdd menu to a frame and implement the menu action
9. Menu action: Close a frame fromMenu action: Close a frame from
10. Add Menu to Parent MDI Frame when opening a childred FrameAdd Menu to Parent MDI Frame when opening a childred Frame
w__ww_.__j_a__v_a__2_s___.c_o___m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.