当前位置:首页 > 网络编程 > WEB编程 > ASP.net > asp.net 的菜单制作(asp.net 的菜单application)

asp.net 的菜单制作(asp.net 的菜单application)

点击次数:22 次 发布日期:2008-11-26 23:17:35 作者:源代码网
源代码网推荐 Imports System
源代码网推荐Imports System.ComponentModel
源代码网推荐Imports System.Drawing
源代码网推荐Imports System.WinForms

Namespace Microsoft.Samples.WinForms.VB.Menus

Public Class Menus
源代码网推荐Inherits System.WinForms.Form

Private components As System.ComponentModel.Container
源代码网推荐Private label1 As System.WinForms.Label
源代码网推荐Private mainMenu As System.WinForms.MainMenu
源代码网推荐Private label1ContextMenu As System.WinForms.ContextMenu

Private Class FontSizes
源代码网推荐public shared Small As Single = 8f
源代码网推荐public shared Medium As Single = 12f
源代码网推荐public shared Large As Single = 24f
源代码网推荐End Class

"Font face and size
源代码网推荐Private fontFace As String = "Arial"
源代码网推荐Private fontSize As Single = FontSizes.Medium

"Used to track which menu items are checked/unchecked
源代码网推荐Private mmiArial As MenuItem
源代码网推荐Private mmiTimesNewRoman As MenuItem
源代码网推荐Private mmiCourier As MenuItem
源代码网推荐Private mmiSmall As MenuItem
源代码网推荐Private mmiMedium As MenuItem
源代码网推荐Private mmiLarge As MenuItem
源代码网推荐Private cmiArial As MenuItem
源代码网推荐Private cmiTimesNewRoman As MenuItem
源代码网推荐Private cmiCourier As MenuItem
源代码网推荐Private cmiSmall As MenuItem
源代码网推荐Private cmiMedium As MenuItem
源代码网推荐Private cmiLarge As MenuItem

Private miMainFormatFontChecked As MenuItem
源代码网推荐Private miMainFormatSizeChecked As MenuItem
源代码网推荐Private miContextFormatFontChecked As MenuItem
源代码网推荐Private miContextFormatSizeChecked As MenuItem

Public Sub New()

MyBase.New

" Required by the Windows Forms Designer
源代码网推荐InitializeComponent

" TODO: Add any constructor code after InitializeComponent call

label1.Font = new Font(fontFace, fontSize)

"Add File Menu
源代码网推荐Dim miFile As MenuItem = mainMenu.MenuItems.Add("&File")
源代码网推荐miFile.MenuItems.Add(new MenuItem("&Open...", new EventHandler(AddressOf Me.FileOpen_Clicked), Shortcut.CtrlO))
源代码网推荐miFile.MenuItems.Add("-") " Gives us a seperator
源代码网推荐miFile.MenuItems.Add(new MenuItem("E&xit", new EventHandler(AddressOf Me.FileExit_Clicked), Shortcut.CtrlX))

"Add Format Menu
源代码网推荐Dim miFormat As MenuItem = mainMenu.MenuItems.Add("F&ormat")

"Font Face sub-menu
源代码网推荐mmiArial = new MenuItem("&Arial", AddressOf Me.FormatFont_Clicked)
源代码网推荐mmiArial.Checked = true
源代码网推荐mmiArial.DefaultItem = true
源代码网推荐mmiTimesNewRoman = new MenuItem("&Times New Roman", AddressOf Me.FormatFont_Clicked)
源代码网推荐mmiCourier = new MenuItem("&Courier New", AddressOf Me.FormatFont_Clicked)

miFormat.MenuItems.Add( "Font &Face" _
源代码网推荐, new EventHandler(AddressOf Me.FormatFont_Clicked) _
源代码网推荐, (new MenuItem(){ mmiArial, mmiTimesNewRoman, mmiCourier }))

"Font Size sub-menu
源代码网推荐mmiSmall = new MenuItem("&Small", AddressOf Me.FormatSize_Clicked)
源代码网推荐mmiMedium = new MenuItem("&Medium", AddressOf Me.FormatSize_Clicked)
源代码网推荐mmiMedium.Checked = true
源代码网推荐mmiMedium.DefaultItem = true
源代码网推荐mmiLarge = new MenuItem("&Large", AddressOf Me.FormatSize_Clicked)

miFormat.MenuItems.Add( "Font &Size" _
源代码网推荐, new EventHandler(AddressOf Me.FormatSize_Clicked) _
源代码网推荐, (new MenuItem(){ mmiSmall, mmiMedium, mmiLarge }))

"Add Format to label context menu
源代码网推荐"Note have to add a clone because menus can"t belong to 2 parents
源代码网推荐label1ContextMenu.MenuItems.Add(miFormat.CloneMenu)

" Set up the context menu items - we use these to check and uncheck items
源代码网推荐cmiArial = label1ContextMenu.MenuItems(0).MenuItems(0).MenuItems(0)
源代码网推荐cmiTimesNewRoman = label1ContextMenu.MenuItems(0).MenuItems(0).MenuItems(1)
源代码网推荐cmiCourier = label1ContextMenu.MenuItems(0).MenuItems(0).MenuItems(2)
源代码网推荐cmiSmall = label1ContextMenu.MenuItems(0).MenuItems(1).MenuItems(0)
源代码网推荐cmiMedium = label1ContextMenu.MenuItems(0).MenuItems(1).MenuItems(1)
源代码网推荐cmiLarge = label1ContextMenu.MenuItems(0).MenuItems(1).MenuItems(2)

"We use these to track which menu items are checked
源代码网推荐"This is made more complex because we have both a menu and a context menu
源代码网推荐miMainFormatFontChecked = mmiArial
源代码网推荐miMainFormatSizeChecked = mmiMedium
源代码网推荐miContextFormatFontChecked = cmiArial
源代码网推荐miContextFormatSizeChecked = cmiMedium

End Sub

"File->Exit Menu item handler
源代码网推荐Private Sub FileExit_Clicked(sender As object, e As System.EventArgs)
源代码网推荐Me.Close
源代码网推荐End Sub

"File->Open Menu item handler
源代码网推荐Private Sub FileOpen_Clicked(sender As object, e As System.EventArgs)
源代码网推荐MessageBox.Show("And why would this open a file?")
源代码网推荐End Sub

"Format->Font Menu item handler
源代码网推荐Private Sub FormatFont_Clicked(sender As object, e As System.EventArgs)

Dim miClicked As MenuItem = CType(sender, MenuItem)

miMainFormatFontChecked.Checked = false
源代码网推荐miContextFormatFontChecked.Checked = false

fontFace = miClicked.Text.Remove(0,1) "Strip off & from menu item text

If (fontFace = "Arial") Then
源代码网推荐miMainFormatFontChecked = mmiArial
源代码网推荐miContextFormatFontChecked = cmiArial
源代码网推荐Else If (fontFace = "Times New Roman") Then
源代码网推荐miMainFormatFontChecked = mmiTimesNewRoman
源代码网推荐miContextFormatFontChecked = cmiTimesNewRoman
源代码网推荐Else
源代码网推荐miMainFormatFontChecked = mmiCourier
源代码网推荐miContextFormatFontChecked = cmiCourier
源代码网推荐End If

miMainFormatFontChecked.Checked = true
源代码网推荐miContextFormatFontChecked.Checked = true

label1.Font = new Font(fontFace, fontSize)

End Sub

"Format->Size Menu item handler
源代码网推荐Private Sub FormatSize_Clicked(sender As object, e As System.EventArgs)

Dim miClicked As MenuItem = CType(sender, MenuItem)

miMainFormatSizeChecked.Checked = false
源代码网推荐miContextFormatSizeChecked.Checked = false

Dim fontSizeString As String = miClicked.Text

If (fontSizeString = "&Small") Then
源代码网推荐miMainFormatSizeChecked = mmiSmall
源代码网推荐miContextFormatSizeChecked = cmiSmall
源代码网推荐fontSize = FontSizes.Small
源代码网推荐Else If (fontSizeString = "&Large")
源代码网推荐miMainFormatSizeChecked = mmiLarge
源代码网推荐miContextFormatSizeChecked = cmiLarge
源代码网推荐fontSize = FontSizes.Large
源代码网推荐Else
源代码网推荐miMainFormatSizeChecked = mmiMedium
源代码网推荐miContextFormatSizeChecked = cmiMedium
源代码网推荐fontSize = FontSizes.Medium
源代码网推荐End If

miMainFormatSizeChecked.Checked = true
源代码网推荐miContextFormatSizeChecked.Checked = true

label1.Font = new Font(fontFace, fontSize)
源代码网推荐End Sub


源代码网推荐"Clean up any resources being used
源代码网推荐Overrides Public Sub Dispose()
源代码网推荐MyBase.Dispose
源代码网推荐components.Dispose
源代码网推荐End Sub


源代码网推荐Private Sub InitializeComponent()

Me.components = new System.ComponentModel.Container()
源代码网推荐Me.label1 = new System.WinForms.Label()
源代码网推荐Me.mainMenu = new System.WinForms.MainMenu()
源代码网推荐Me.label1ContextMenu = new System.WinForms.ContextMenu()

Me.AutoScaleBaseSize = new System.Drawing.Size(5, 13)
源代码网推荐Me.Text = "Menus "R Us"
源代码网推荐Me.Menu = mainMenu
源代码网推荐Me.ClientSize = new System.Drawing.Size(392, 117)

label1.Anchor = System.WinForms.AnchorStyles.TopLeftRight
源代码网推荐label1.BackColor = System.Drawing.Color.LightSteelBlue
源代码网推荐label1.ContextMenu = label1ContextMenu
源代码网推荐label1.Location = new System.Drawing.Point(16, 24)
源代码网推荐label1.Text = "Right Click on me - I have a context menu!"
源代码网推荐label1.TabIndex = 0
源代码网推荐label1.Size = new System.Drawing.Size(360, 50)

Me.Controls.Add(label1)
源代码网推荐End Sub


源代码网推荐"Run the application
源代码网推荐"The main entry point for the application
源代码网推荐Shared Sub Main()
源代码网推荐System.WinForms.Application.Run(New Menus())
源代码网推荐End Sub

End Class

End Namespace


源代码网推荐作者:jspfuns


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华