网站首页站长博客下载中心域名交易站长论坛域名主机免费电邮免费域名中文排行排名查询站长书库书籍教程下载
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
学院首页 网络编程 网页设计 图形图象 数 据 库 服 务 器 网络媒体 网络安全 个人专栏 站长CLUB 业界新闻 信息公告
 当前位置:首页 >> 网络编程 >> NET专区 >> 正文
公告通知
返回上级列表
资料搜索
相关文章
asp.net 的菜单制作(asp.net 的菜单application)
[ 来源: | 作者: | 时间:2004-6-22 12:40:00 | 浏览:人次 ]
收藏到新浪ViVi 收藏到365KEY 收藏到我摘  字号选择〖    〗/ 双击滚屏 单击停止  
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


[发送给好友]  [打印本页]  [关闭窗口]  [返回顶部]   转载请注明来源:http://edu.chinaz.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
栏目编辑: 设计风 责任编辑: chinaz.com
原始作者: 录入时间: 2004-6-22 12:40:00
信息来源: 投稿信箱: Edu#chinaz.com
设为首页 - 加入收藏 - 关于我们 - 广告服务 - 版权申明 - 友情链接 - 联系方式 - 总编信箱 - 会员投稿