VB.Net Tutorial/GUI/Menu — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:56, 26 мая 2010
Содержание
Add Menu to Form window and attach actions
Imports System.Windows.Forms
public class CreateMenuAndAttachAction
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Inherits System.Windows.Forms.Form
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
Private components As System.ruponentModel.IContainer
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem10 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem11 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem12 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem13 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem14 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem15 As System.Windows.Forms.MenuItem
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem8 = New System.Windows.Forms.MenuItem
Me.MenuItem9 = New System.Windows.Forms.MenuItem
Me.MenuItem10 = New System.Windows.Forms.MenuItem
Me.MenuItem11 = New System.Windows.Forms.MenuItem
Me.MenuItem12 = New System.Windows.Forms.MenuItem
Me.MenuItem13 = New System.Windows.Forms.MenuItem
Me.MenuItem14 = New System.Windows.Forms.MenuItem
Me.MenuItem15 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.MenuItem4 = New System.Windows.Forms.MenuItem
Me.MenuItem5 = New System.Windows.Forms.MenuItem
Me.MenuItem6 = New System.Windows.Forms.MenuItem
Me.MenuItem7 = New System.Windows.Forms.MenuItem
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
"
"MainMenu1
"
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem5, Me.MenuItem6, Me.MenuItem7})
"
"MenuItem1
"
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem8, Me.MenuItem11, Me.MenuItem12, Me.MenuItem13, Me.MenuItem14, Me.MenuItem15})
Me.MenuItem1.Text = "File"
"
"MenuItem8
"
Me.MenuItem8.Index = 0
Me.MenuItem8.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem9, Me.MenuItem10})
Me.MenuItem8.Text = "New"
"
"MenuItem9
"
Me.MenuItem9.Index = 0
Me.MenuItem9.Text = "File"
"
"MenuItem10
"
Me.MenuItem10.Index = 1
Me.MenuItem10.Text = "Project"
"
"MenuItem11
"
Me.MenuItem11.Index = 1
Me.MenuItem11.Text = "Open"
"
"MenuItem12
"
Me.MenuItem12.Index = 2
Me.MenuItem12.Text = "Save"
"
"MenuItem13
"
Me.MenuItem13.Index = 3
Me.MenuItem13.Text = "-"
"
"MenuItem14
"
Me.MenuItem14.Index = 4
Me.MenuItem14.Text = "New"
"
"MenuItem15
"
Me.MenuItem15.Index = 5
Me.MenuItem15.Text = "Add"
"
"MenuItem2
"
Me.MenuItem2.Index = 1
Me.MenuItem2.Text = "Edit"
"
"MenuItem3
"
Me.MenuItem3.Index = 2
Me.MenuItem3.Text = "View"
"
"MenuItem4
"
Me.MenuItem4.Index = 3
Me.MenuItem4.Text = "Project"
"
"MenuItem5
"
Me.MenuItem5.Index = 4
Me.MenuItem5.Text = "Create"
"
"MenuItem6
"
Me.MenuItem6.Index = 5
Me.MenuItem6.Text = "Tool"
"
"MenuItem7
"
Me.MenuItem7.Index = 6
Me.MenuItem7.Text = "Debug"
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(368, 198)
Me.Menu = Me.MainMenu1
End Sub
Private Sub MenuItem11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem11.Click
OpenFileDialog1.ShowDialog()
End Sub
Private Sub MenuItem12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem12.Click
SaveFileDialog1.ShowDialog()
End Sub
End Class
"Visual Basic 2005 Cookbook Solutions for VB 2005 Programmers
"by Tim Patrick (Author), John Craig (Author)
"# Publisher: O"Reilly Media, Inc. (September 21, 2006)
"# Language: English
"# ISBN-10: 0596101775
"# ISBN-13: 978-0596101770
Imports MVB = Microsoft.VisualBasic
Imports System.Windows.Forms
public class BuildYourOwnMenu
public Shared Sub Main
Application.Run(New Form1)
End Sub
End class
Public Class Form1
Private Declare Auto Function GetPrivateProfileString Lib "kernel32" _
(ByVal AppName As String, _
ByVal KeyName As String, _
ByVal DefaultValue As String, _
ByVal ReturnedString As System.Text.StringBuilder, _
ByVal BufferSize As Integer, _
ByVal FileName As String) As Integer
Private Sub MenuExitProgram_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuExitProgram.Click
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim favoritesPath As String
favoritesPath = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)
If (favoritesPath = "") Then Return
If (My.ruputer.FileSystem.DirectoryExists(favoritesPath) = False) Then Return
BuildFavorites(MenuFavorites, favoritesPath)
If (MenuFavorites.DropDownItems.Count > 1) Then _
MenuNoFavorites.Visible = False
End Sub
Private Sub BuildFavorites(ByVal whichMenu As ToolStripMenuItem, ByVal fromPath As String)
Dim oneEntry As String
Dim menuEntry As ToolStripMenuItem
Dim linkPath As String
Dim displayName As String
For Each oneEntry In My.ruputer.FileSystem.GetDirectories(fromPath)
menuEntry = New ToolStripMenuItem( _
My.ruputer.FileSystem.GetName(oneEntry))
BuildFavorites(menuEntry, oneEntry)
If (menuEntry.DropDownItems.Count > 0) Then _
whichMenu.DropDownItems.Add(menuEntry)
Next oneEntry
For Each oneEntry In My.ruputer.FileSystem.GetFiles(fromPath, _
FileIO.SearchOption.SearchTopLevelOnly, "*.url")
linkPath = GetINIEntry("InternetShortcut", "URL", oneEntry)
If (linkPath <> "") Then
displayName = My.ruputer.FileSystem.GetName(oneEntry)
displayName = MVB.Left(displayName, displayName.Length - 4)
menuEntry = New ToolStripMenuItem(displayName)
menuEntry.Tag = linkPath
whichMenu.DropDownItems.Add(menuEntry)
AddHandler menuEntry.Click, AddressOf RunFavoritesLink
End If
Next oneEntry
End Sub
Private Sub RunFavoritesLink(ByVal sender As System.Object, ByVal e As System.EventArgs)
" ----- Run the link.
Dim whichMenu As ToolStripMenuItem
whichMenu = CType(sender, ToolStripMenuItem)
Console.WriteLine(whichMenu.Tag)
"Process.Start(whichMenu.Tag)
End Sub
Private Function GetINIEntry(ByVal sectionName As String, _
ByVal keyName As String, ByVal whichFile As String) As String
" ----- Extract a value from an INI-style file.
Dim resultLength As Integer
Dim targetBuffer As New System.Text.StringBuilder(500)
resultLength = GetPrivateProfileString(sectionName, keyName, "", _
targetBuffer, targetBuffer.Capacity, whichFile)
Return targetBuffer.ToString()
End Function
End Class
<Global.Microsoft.VisualBasic.rupilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
"Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.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.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.MainMenu = New System.Windows.Forms.MenuStrip
Me.MenuFile = New System.Windows.Forms.ToolStripMenuItem
Me.MenuExitProgram = New System.Windows.Forms.ToolStripMenuItem
Me.MenuFavorites = New System.Windows.Forms.ToolStripMenuItem
Me.MenuNoFavorites = New System.Windows.Forms.ToolStripMenuItem
Me.MainMenu.SuspendLayout()
Me.SuspendLayout()
"
"MainMenu
"
Me.MainMenu.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.MenuFile, Me.MenuFavorites})
Me.MainMenu.Location = New System.Drawing.Point(0, 0)
Me.MainMenu.Name = "MainMenu"
Me.MainMenu.Size = New System.Drawing.Size(292, 24)
Me.MainMenu.TabIndex = 0
Me.MainMenu.Text = "MenuStrip1"
"
"MenuFile
"
Me.MenuFile.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.MenuExitProgram})
Me.MenuFile.Name = "MenuFile"
Me.MenuFile.Size = New System.Drawing.Size(35, 20)
Me.MenuFile.Text = "&File"
"
"MenuExitProgram
"
Me.MenuExitProgram.Name = "MenuExitProgram"
Me.MenuExitProgram.ShortcutKeys = CType((System.Windows.Forms.Keys.Alt Or System.Windows.Forms.Keys.F4), System.Windows.Forms.Keys)
Me.MenuExitProgram.Size = New System.Drawing.Size(132, 22)
Me.MenuExitProgram.Text = "E&xit"
"
"MenuFavorites
"
Me.MenuFavorites.DropDownItems.AddRange(New System.Windows.Forms.ToolStripItem() {Me.MenuNoFavorites})
Me.MenuFavorites.Name = "MenuFavorites"
Me.MenuFavorites.Size = New System.Drawing.Size(64, 20)
Me.MenuFavorites.Text = "Fa&vorites"
"
"MenuNoFavorites
"
Me.MenuNoFavorites.Enabled = False
Me.MenuNoFavorites.Name = "MenuNoFavorites"
Me.MenuNoFavorites.Size = New System.Drawing.Size(112, 22)
Me.MenuNoFavorites.Text = "(empty)"
"
"Form1
"
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(292, 121)
Me.Controls.Add(Me.MainMenu)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
Me.MainMenuStrip = Me.MainMenu
Me.MaximizeBox = False
Me.Name = "Form1"
Me.Text = "Runtime Menus"
Me.MainMenu.ResumeLayout(False)
Me.MainMenu.PerformLayout()
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents MainMenu As System.Windows.Forms.MenuStrip
Friend WithEvents MenuFile As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents MenuExitProgram As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents MenuFavorites As System.Windows.Forms.ToolStripMenuItem
Friend WithEvents MenuNoFavorites As System.Windows.Forms.ToolStripMenuItem
End Class
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
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class OwnerDrawMenuAndSubmenu
public Shared Sub Main
Application.Run(New 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 Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
"Required by the Windows Form Designer
Private components As System.ruponentModel.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 MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem2 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem3 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem4 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem8 As System.Windows.Forms.MenuItem
Friend WithEvents MenuItem9 As System.Windows.Forms.MenuItem
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItem2 = New System.Windows.Forms.MenuItem
Me.MenuItem7 = New System.Windows.Forms.MenuItem
Me.MenuItem8 = New System.Windows.Forms.MenuItem
Me.MenuItem9 = New System.Windows.Forms.MenuItem
Me.MenuItem3 = New System.Windows.Forms.MenuItem
Me.MenuItem4 = New System.Windows.Forms.MenuItem
Me.MenuItem5 = New System.Windows.Forms.MenuItem
Me.MenuItem6 = New System.Windows.Forms.MenuItem
Me.SuspendLayout()
"
"MainMenu1
"
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
"
"MenuItem1
"
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem2, Me.MenuItem3, Me.MenuItem4, Me.MenuItem5, Me.MenuItem6})
Me.MenuItem1.Text = "&File"
"
"MenuItem2
"
Me.MenuItem2.Index = 0
Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem7, Me.MenuItem8, Me.MenuItem9})
Me.MenuItem2.Text = "Item 1"
"
"MenuItem7
"
Me.MenuItem7.Index = 0
Me.MenuItem7.OwnerDraw = True
Me.MenuItem7.Text = "Item 5"
"
"MenuItem8
"
Me.MenuItem8.Checked = True
Me.MenuItem8.Index = 1
Me.MenuItem8.Text = "Item 6"
"
"MenuItem9
"
Me.MenuItem9.Index = 2
Me.MenuItem9.Text = "Item 7"
"
"MenuItem3
"
Me.MenuItem3.Index = 1
Me.MenuItem3.Text = "Item 2"
"
"MenuItem4
"
Me.MenuItem4.Index = 2
Me.MenuItem4.Text = "Item 3"
"
"MenuItem5
"
Me.MenuItem5.Index = 3
Me.MenuItem5.Text = "-"
"
"MenuItem6
"
Me.MenuItem6.Index = 4
Me.MenuItem6.Shortcut = System.Windows.Forms.Shortcut.CtrlX
Me.MenuItem6.Text = "E&xit"
"
"Form1
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Menu = Me.MainMenu1
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub MenuItem6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem6.Click
End
End Sub
Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem9.Click
MsgBox("You clicked Item 7.")
End Sub
Private Sub MenuItem8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click
MenuItem8.Checked = Not MenuItem8.Checked
End Sub
Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem4.Click
MenuItem4.Visible = False
End Sub
Private Sub MenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
MenuItem3.Enabled = False
End Sub
Private Sub MenuItem7_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles MenuItem7.MeasureItem
e.ItemHeight = 15
e.ItemWidth = 60
End Sub
Private Sub MenuItem7_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles MenuItem7.DrawItem
Dim penRed As New Pen(Color.Red)
e.Graphics.DrawEllipse(penRed, e.Bounds)
End Sub
End Class
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
public class FormMenuAction
public Shared Sub Main
Application.Run(New FrmMenu)
End Sub
End class
Public Class FrmMenu
Inherits 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 Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
" display label
Friend WithEvents lblDisplay As Label
" main menu (contains file and format menus)
Friend WithEvents mnuMainMenu As MainMenu
" file menu
Friend WithEvents mnuFile As MenuItem
Friend WithEvents mnuitmAbout As MenuItem
Friend WithEvents mnuitmExit As MenuItem
" format menu (contains format and font submenus)
Friend WithEvents mnuFormat As MenuItem
" color submenu
Friend WithEvents mnuitmColor As MenuItem
Friend WithEvents mnuitmBlack As MenuItem
Friend WithEvents mnuitmBlue As MenuItem
Friend WithEvents mnuitmRed As MenuItem
Friend WithEvents mnuitmGreen As MenuItem
" font submenu
Friend WithEvents mnuitmFont As MenuItem
Friend WithEvents mnuitmTimes As MenuItem
Friend WithEvents mnuitmCourier As MenuItem
Friend WithEvents mnuitmComic As MenuItem
Friend WithEvents mnuitmDash As MenuItem
Friend WithEvents mnuitmBold As MenuItem
Friend WithEvents mnuitmItalic As MenuItem
"Required by the Windows Form Designer
Private components As System.ruponentModel.Container
"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.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.mnuitmItalic = New System.Windows.Forms.MenuItem()
Me.mnuitmExit = New System.Windows.Forms.MenuItem()
Me.mnuitmCourier = New System.Windows.Forms.MenuItem()
Me.mnuitmBlue = New System.Windows.Forms.MenuItem()
Me.mnuitmGreen = New System.Windows.Forms.MenuItem()
Me.mnuMainMenu = New System.Windows.Forms.MainMenu()
Me.mnuFile = New System.Windows.Forms.MenuItem()
Me.mnuitmAbout = New System.Windows.Forms.MenuItem()
Me.mnuFormat = New System.Windows.Forms.MenuItem()
Me.mnuitmColor = New System.Windows.Forms.MenuItem()
Me.mnuitmBlack = New System.Windows.Forms.MenuItem()
Me.mnuitmRed = New System.Windows.Forms.MenuItem()
Me.mnuitmFont = New System.Windows.Forms.MenuItem()
Me.mnuitmTimes = New System.Windows.Forms.MenuItem()
Me.mnuitmComic = New System.Windows.Forms.MenuItem()
Me.mnuitmDash = New System.Windows.Forms.MenuItem()
Me.mnuitmBold = New System.Windows.Forms.MenuItem()
Me.lblDisplay = New System.Windows.Forms.Label()
Me.SuspendLayout()
"
"mnuitmItalic
"
Me.mnuitmItalic.Index = 5
Me.mnuitmItalic.Text = "Italic"
"
"mnuitmExit
"
Me.mnuitmExit.Index = 1
Me.mnuitmExit.Text = "Exit"
"
"mnuitmCourier
"
Me.mnuitmCourier.Index = 1
Me.mnuitmCourier.Text = "Courier"
"
"mnuitmBlue
"
Me.mnuitmBlue.Index = 1
Me.mnuitmBlue.RadioCheck = True
Me.mnuitmBlue.Text = "Blue"
"
"mnuitmGreen
"
Me.mnuitmGreen.Index = 3
Me.mnuitmGreen.RadioCheck = True
Me.mnuitmGreen.Text = "Green"
"
"mnuMainMenu
"
Me.mnuMainMenu.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile, Me.mnuFormat})
"
"mnuFile
"
Me.mnuFile.Index = 0
Me.mnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuitmAbout, Me.mnuitmExit})
Me.mnuFile.Text = "File "
"
"mnuitmAbout
"
Me.mnuitmAbout.Index = 0
Me.mnuitmAbout.Text = "About"
"
"mnuFormat
"
Me.mnuFormat.Index = 1
Me.mnuFormat.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuitmColor, Me.mnuitmFont})
Me.mnuFormat.Text = "Format"
"
"mnuitmColor
"
Me.mnuitmColor.Index = 0
Me.mnuitmColor.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuitmBlack, Me.mnuitmBlue, Me.mnuitmRed, Me.mnuitmGreen})
Me.mnuitmColor.Text = "Color"
"
"mnuitmBlack
"
Me.mnuitmBlack.Index = 0
Me.mnuitmBlack.RadioCheck = True
Me.mnuitmBlack.Text = "Black"
"
"mnuitmRed
"
Me.mnuitmRed.Index = 2
Me.mnuitmRed.RadioCheck = True
Me.mnuitmRed.Text = "Red"
"
"mnuitmFont
"
Me.mnuitmFont.Index = 1
Me.mnuitmFont.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuitmTimes, Me.mnuitmCourier, Me.mnuitmComic, Me.mnuitmDash, Me.mnuitmBold, Me.mnuitmItalic})
Me.mnuitmFont.Text = "Font"
"
"mnuitmTimes
"
Me.mnuitmTimes.Index = 0
Me.mnuitmTimes.Text = "Times New Roman"
"
"mnuitmComic
"
Me.mnuitmComic.Index = 2
Me.mnuitmComic.Text = "Comic Sans"
"
"mnuitmDash
"
Me.mnuitmDash.Index = 3
Me.mnuitmDash.Text = "-"
"
"mnuitmBold
"
Me.mnuitmBold.Index = 4
Me.mnuitmBold.Text = "Bold"
"
"lblDisplay
"
Me.lblDisplay.Font = New System.Drawing.Font("Times New Roman", 26.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.lblDisplay.Location = New System.Drawing.Point(8, 8)
Me.lblDisplay.Name = "lblDisplay"
Me.lblDisplay.Size = New System.Drawing.Size(240, 48)
Me.lblDisplay.TabIndex = 0
Me.lblDisplay.Text = "www.vbex.ru"
"
"FrmMenu
"
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(256, 121)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblDisplay})
Me.Menu = Me.mnuMainMenu
Me.Name = "FrmMenu"
Me.Text = "MenuTest"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub mnuitmAbout_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmAbout.Click
MessageBox.Show("This is an example" & vbCrLf & _
"of using menus.", "About", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End Sub
Private Sub mnuitmExit_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmExit.Click
Application.Exit()
End Sub
Private Sub ClearColor()
mnuitmBlack.Checked = False
mnuitmBlue.Checked = False
mnuitmRed.Checked = False
mnuitmGreen.Checked = False
End Sub
Private Sub mnuitmBlack_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmBlack.Click
ClearColor()
lblDisplay.ForeColor = Color.Black
mnuitmBlack.Checked = True
End Sub
Private Sub mnuitmBlue_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmBlue.Click
ClearColor()
lblDisplay.ForeColor = Color.Blue
mnuitmBlue.Checked = True
End Sub
Private Sub mnuitmRed_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmRed.Click
ClearColor()
lblDisplay.ForeColor = Color.Red
mnuitmRed.Checked = True
End Sub
Private Sub mnuitmGreen_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmGreen.Click
ClearColor()
lblDisplay.ForeColor = Color.Green
mnuitmGreen.Checked = True
End Sub
Private Sub ClearFont()
mnuitmTimes.Checked = False
mnuitmCourier.Checked = False
mnuitmComic.Checked = False
End Sub
Private Sub mnuitmTimes_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmTimes.Click
ClearFont()
mnuitmTimes.Checked = True
lblDisplay.Font = New Font("Times New Roman", 30, _
lblDisplay.Font.Style)
End Sub
Private Sub mnuitmCourier_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmCourier.Click
ClearFont()
mnuitmCourier.Checked = True
lblDisplay.Font = New Font("Courier New", 30, _
lblDisplay.Font.Style)
End Sub
Private Sub mnuitmComic_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmComic.Click
ClearFont()
mnuitmComic.Checked = True
lblDisplay.Font = New Font("Comic Sans MS", 30, _
lblDisplay.Font.Style)
End Sub
Private Sub mnuitmBold_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmBold.Click
mnuitmBold.Checked = Not mnuitmBold.Checked
lblDisplay.Font = New Font("Times New Roman", 30, lblDisplay.Font.Style Xor FontStyle.Bold)
End Sub
Private Sub mnuitmItalic_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuitmItalic.Click
mnuitmItalic.Checked = Not mnuitmItalic.Checked
lblDisplay.Font = New Font("Times New Roman", 30, lblDisplay.Font.Style Xor FontStyle.Italic)
End Sub
End Class