📄 frmmain.vb
字号:
'
' Chapter 02 - Completed Solution
'
' MCSD Guide to Developing Desktop Applications
' with Microsoft Visual Basic .NET
'
' Copyright (C) 2004 Course Technology
' All rights reserved.
Option Explicit On
Option Strict On
Public Class frmMain
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.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 mmuMain As System.Windows.Forms.MainMenu
Friend WithEvents mmuFile As System.Windows.Forms.MenuItem
Friend WithEvents mmuFileExit As System.Windows.Forms.MenuItem
Friend WithEvents txtFlightNumber As System.Windows.Forms.TextBox
Friend WithEvents grpType As System.Windows.Forms.GroupBox
Friend WithEvents rad757 As System.Windows.Forms.RadioButton
Friend WithEvents rad777 As System.Windows.Forms.RadioButton
Friend WithEvents mmuDisplay As System.Windows.Forms.MenuItem
Friend WithEvents mmuDisplayAirplane As System.Windows.Forms.MenuItem
Friend WithEvents lstOrigin As System.Windows.Forms.ListBox
Friend WithEvents lstDestination As System.Windows.Forms.ListBox
Friend WithEvents lblPromptOrigin As System.Windows.Forms.Label
Friend WithEvents lblPromptDestination As System.Windows.Forms.Label
Friend WithEvents lblPromptFlightNumber As System.Windows.Forms.Label
Friend WithEvents mmuHelp As System.Windows.Forms.MenuItem
Friend WithEvents mmuHelpAbout As System.Windows.Forms.MenuItem
Friend WithEvents tipGeneral As System.Windows.Forms.ToolTip
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.mmuMain = New System.Windows.Forms.MainMenu()
Me.mmuFile = New System.Windows.Forms.MenuItem()
Me.mmuFileExit = New System.Windows.Forms.MenuItem()
Me.mmuDisplay = New System.Windows.Forms.MenuItem()
Me.mmuDisplayAirplane = New System.Windows.Forms.MenuItem()
Me.mmuHelp = New System.Windows.Forms.MenuItem()
Me.mmuHelpAbout = New System.Windows.Forms.MenuItem()
Me.txtFlightNumber = New System.Windows.Forms.TextBox()
Me.grpType = New System.Windows.Forms.GroupBox()
Me.rad777 = New System.Windows.Forms.RadioButton()
Me.rad757 = New System.Windows.Forms.RadioButton()
Me.lstOrigin = New System.Windows.Forms.ListBox()
Me.lstDestination = New System.Windows.Forms.ListBox()
Me.lblPromptOrigin = New System.Windows.Forms.Label()
Me.lblPromptDestination = New System.Windows.Forms.Label()
Me.lblPromptFlightNumber = New System.Windows.Forms.Label()
Me.tipGeneral = New System.Windows.Forms.ToolTip(Me.components)
Me.grpType.SuspendLayout()
Me.SuspendLayout()
'
'mmuMain
'
Me.mmuMain.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mmuFile, Me.mmuDisplay, Me.mmuHelp})
'
'mmuFile
'
Me.mmuFile.Index = 0
Me.mmuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mmuFileExit})
Me.mmuFile.Text = "&File"
'
'mmuFileExit
'
Me.mmuFileExit.Index = 0
Me.mmuFileExit.Text = "E&xit"
'
'mmuDisplay
'
Me.mmuDisplay.Index = 1
Me.mmuDisplay.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mmuDisplayAirplane})
Me.mmuDisplay.Text = "&Display"
'
'mmuDisplayAirplane
'
Me.mmuDisplayAirplane.Index = 0
Me.mmuDisplayAirplane.Text = "&Airplane"
'
'mmuHelp
'
Me.mmuHelp.Index = 2
Me.mmuHelp.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mmuHelpAbout})
Me.mmuHelp.Text = "&Help"
'
'mmuHelpAbout
'
Me.mmuHelpAbout.Index = 0
Me.mmuHelpAbout.Text = "&About"
'
'txtFlightNumber
'
Me.txtFlightNumber.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.txtFlightNumber.Location = New System.Drawing.Point(144, 48)
Me.txtFlightNumber.Name = "txtFlightNumber"
Me.txtFlightNumber.Size = New System.Drawing.Size(96, 20)
Me.txtFlightNumber.TabIndex = 14
Me.txtFlightNumber.Text = ""
'
'grpType
'
Me.grpType.Controls.AddRange(New System.Windows.Forms.Control() {Me.rad777, Me.rad757})
Me.grpType.Location = New System.Drawing.Point(16, 16)
Me.grpType.Name = "grpType"
Me.grpType.Size = New System.Drawing.Size(112, 96)
Me.grpType.TabIndex = 15
Me.grpType.TabStop = False
Me.grpType.Text = "Airplane Type"
'
'rad777
'
Me.rad777.Location = New System.Drawing.Point(16, 48)
Me.rad777.Name = "rad777"
Me.rad777.Size = New System.Drawing.Size(48, 24)
Me.rad777.TabIndex = 3
Me.rad777.Text = "777"
'
'rad757
'
Me.rad757.Location = New System.Drawing.Point(16, 24)
Me.rad757.Name = "rad757"
Me.rad757.Size = New System.Drawing.Size(56, 24)
Me.rad757.TabIndex = 1
Me.rad757.Text = "757"
'
'lstOrigin
'
Me.lstOrigin.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lstOrigin.Items.AddRange(New Object() {"Atlanta", "Chicago", "Los Angeles", "New York"})
Me.lstOrigin.Location = New System.Drawing.Point(16, 136)
Me.lstOrigin.Name = "lstOrigin"
Me.lstOrigin.Size = New System.Drawing.Size(104, 106)
Me.lstOrigin.TabIndex = 16
Me.tipGeneral.SetToolTip(Me.lstOrigin, "Click to select the origin of the flight.")
'
'lstDestination
'
Me.lstDestination.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.lstDestination.Location = New System.Drawing.Point(128, 136)
Me.lstDestination.Name = "lstDestination"
Me.lstDestination.Size = New System.Drawing.Size(104, 106)
Me.lstDestination.TabIndex = 17
Me.tipGeneral.SetToolTip(Me.lstDestination, "Click to select the destination of the flight.")
'
'lblPromptOrigin
'
Me.lblPromptOrigin.Location = New System.Drawing.Point(16, 120)
Me.lblPromptOrigin.Name = "lblPromptOrigin"
Me.lblPromptOrigin.Size = New System.Drawing.Size(96, 16)
Me.lblPromptOrigin.TabIndex = 18
Me.lblPromptOrigin.Text = "Origin"
'
'lblPromptDestination
'
Me.lblPromptDestination.Location = New System.Drawing.Point(136, 120)
Me.lblPromptDestination.Name = "lblPromptDestination"
Me.lblPromptDestination.Size = New System.Drawing.Size(96, 16)
Me.lblPromptDestination.TabIndex = 19
Me.lblPromptDestination.Text = "Destination"
'
'lblPromptFlightNumber
'
Me.lblPromptFlightNumber.Location = New System.Drawing.Point(144, 24)
Me.lblPromptFlightNumber.Name = "lblPromptFlightNumber"
Me.lblPromptFlightNumber.Size = New System.Drawing.Size(96, 16)
Me.lblPromptFlightNumber.TabIndex = 20
Me.lblPromptFlightNumber.Text = "Flight Number"
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(296, 273)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblPromptFlightNumber, Me.lblPromptDestination, Me.lblPromptOrigin, Me.lstDestination, Me.lstOrigin, Me.grpType, Me.txtFlightNumber})
Me.Menu = Me.mmuMain
Me.Name = "frmMain"
Me.Text = "Chapter 2 - Completed Solution"
Me.grpType.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
#End Region
' The variable mstrAirplane type is set in the radAirplaneType_CheckedChanged
' procedure. The value is passed to the constructor for the form named frmSeating.
' See the New procedure in the form named frmSeating.
Private mstrAirplaneType As String
' This event handler illusrates a multicast event handler. The Handles clause lists
' two events for each of the two radio buttons. Each event is seperated by a comma.
Private Sub radAirplaneType_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rad757.CheckedChanged, rad777.CheckedChanged
' Declare a local variable to store the Radio Button.
Dim radCurrent As RadioButton
' Because Option Strict is enabled, explicitly convert the generic Object
' type (System.Object) to a RadioButton using the CType function.
radCurrent = CType(sender, System.Windows.Forms.RadioButton)
' Store the Text property of the clicked RadioButton in the variable.
' Again this variable is used in the constructor for the form named
' frmSeating.
mstrAirplaneType = radCurrent.Text
End Sub
' Display the seating form using the information from this form. Note that the
' constructor takes three arguments.
Private Sub mmuDisplayAirplane_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmuDisplayAirplane.Click
' First, create an instance of the form named frmSeating using the three
' arguments. The first is the airplane type, and the second and third
' arguments are the selected items from the two list boxes. Again, because
' Option Strict is enabled, the ToString method must be called because
' the data type of the SelectedItem property is System.Object.
Dim frmSeatingNew As New frmSeating(mstrAirplaneType, _
lstOrigin.SelectedItem.ToString, _
lstDestination.SelectedItem.ToString)
' Display the form as a modeless dialog box.
frmSeatingNew.Show()
' Set the Text property to update the contents of the title bar.
frmSeatingNew.Text = "Flight Number " & txtFlightNumber.Text
End Sub
' Create an instance of the Help About form and display it.
Private Sub mmuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmuHelpAbout.Click
Dim frmAboutNew As New frmAbout()
frmAboutNew.ShowDialog()
End Sub
' Load the Destination list box when the form loads.
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Declare and initialize the array pstrCities. The array will contain
' four memebers. The initialization uses C-style syntax. Each item in the
' list is seperated by a comma, and braces surround the list.
Dim pstrCities As String() = {"Atlanta", "Chicago", "Los Angeles", "New York"}
' The AddRange method adds a range of items (array) to the Items collection
' instead of a single item. To add a single item, call the Add method.
lstDestination.Items.AddRange(pstrCities)
End Sub
' Close the main form.
Private Sub mmuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmuFileExit.Click
Me.Close()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -