📄 frmseating.vb
字号:
' for each airplane type.
Private Const cintCheckBoxHeight As Integer = 15
Private Const cintCheckBoxWidth As Integer = 15
Private Const cint757Seats As Integer = 6
Private Const cint757Rows As Integer = 38
Private Const cint777Seats As Integer = 8
Private Const cint777Rows As Integer = 45
' The variables mintFull and mintEmpty store the number of
' occupied and empty seats on the airplane.
Private mintFull As Integer
Private mintEmpty As Integer
' pntCurrent is used to create a Point structure.
Private pntCurrent As System.Drawing.Point
' All of the work takes place in the ConfigureSeating procedure. This
' procedure is called by the constructor. See the New procedure in the
' Windows Form Designer generated code.
Private Sub ConfigureSeating(ByVal AircraftType As String)
' Variables to store the current seat and the current row.
Dim pintSeatCurrent, pintRowCurrent As Integer
' The Select Case statement configures the airplane based on the
' type of airplane. This value is passed to the procedure, and is
' obtained from the argument passed through the constructor.
Select Case AircraftType
Case "757"
' Redimension the arrays containing the check boxes and
' labels based on the current airplane configuration.
ReDim chkSeats(cint757Seats, cint757Rows)
ReDim lblRow(cint757Rows)
' Define the number of empty seats.
mintEmpty = cint757Seats * cint757Rows
' Create each check box representing a seat.
For pintSeatCurrent = 0 To cint757Seats - 1
For pintRowCurrent = 0 To cint757Rows - 1
pntCurrent = New Point((pintSeatCurrent + 1) * cintCheckBoxWidth, _
(pintRowCurrent + 1) * cintCheckBoxHeight)
Call CreateCheckBox(pintSeatCurrent, pintRowCurrent, pntCurrent)
Next
Next
' Create the labels to identify the rows.
For pintRowCurrent = 0 To cint757Rows - 1
Call CreateLabel(pintRowCurrent)
lblRow(pintRowCurrent).Left = 120
lblRow(pintRowCurrent).Top = (pintRowCurrent + 1) * cintCheckBoxHeight
lblRow(pintRowCurrent).Height = 15
lblRow(pintRowCurrent).Width = 25
Next
Case "777"
ReDim chkSeats(cint777Seats, cint777Rows)
ReDim lblRow(cint777Rows)
mintEmpty = cint777Seats * cint777Rows
For pintSeatCurrent = 0 To cint777Seats - 1
For pintRowCurrent = 0 To cint777Rows - 1
pntCurrent = New Point((pintSeatCurrent + 1) * cintCheckBoxWidth, _
(pintRowCurrent + 1) * cintCheckBoxHeight)
Call CreateCheckBox(pintSeatCurrent, pintRowCurrent, pntCurrent)
Next
Next
For pintRowCurrent = 0 To cint777Rows - 1
Call CreateLabel(pintRowCurrent)
lblRow(pintRowCurrent).Left = 220
lblRow(pintRowCurrent).Top = (pintRowCurrent + 1) * cintCheckBoxHeight
lblRow(pintRowCurrent).Height = 15
lblRow(pintRowCurrent).Width = 25
Next
End Select
End Sub
' The CreateCheckBox procedure is responsible for actually creating
' each CheckBox control instance and adding a reference to the array.
' The current seat and row are passed as arguments, along with the
' position of the check box.
Private Sub CreateCheckBox(ByVal pintSeatCurrent As Integer, ByVal pintRowcurrent As Integer, ByVal pnt As Point)
' Create an instance of the CheckBox control and make it visible.
chkSeats(pintSeatCurrent, pintRowcurrent) = New CheckBox()
chkSeats(pintSeatCurrent, pintRowcurrent).Visible = True
' Define the size of the CheckBox control instance by creating an
' instance of the Size structure and assigning a value to the Size
' property.
chkSeats(pintSeatCurrent, pintRowcurrent).Size = _
New System.Drawing.Size(cintCheckBoxWidth, cintCheckBoxHeight)
' Define the position of the CheckBox control instance.
chkSeats(pintSeatCurrent, pintRowcurrent).Location = pnt
' Add the event handler for the newly created CheckBox control instance.
' The procedure named chkSeats_CheckChanged will handle the CheckedChanged event for
' all of the created check boxes.
AddHandler chkSeats(pintSeatCurrent, pintRowcurrent).CheckedChanged, _
AddressOf chkseats_CheckedChanged
' Finally, add the newly creted CheckBox control instance to the Controls
' collection for the Panel. Note that by adding the control instance to the
' Controls collection of the Panel rather than the form, the control instances
' will be contained by the Panel. The reason is simple. The CheckBox control
' instances will scroll with the Panel instead of the form.
Me.pnlSeats.Controls.Add(chkSeats(pintSeatCurrent, pintRowcurrent))
End Sub
' The CreateLabel procedure is responsible for actually creating each
' Label control instance and adding a reference to the array.
Private Sub CreateLabel(ByVal pintRowCurrent As Integer)
lblRow(pintRowCurrent) = New Label()
lblRow(pintRowCurrent).Visible = True
lblRow(pintRowCurrent).Text = (pintRowCurrent + 1).ToString()
Me.pnlSeats.Controls.Add(lblRow(pintRowCurrent))
End Sub
' The CheckedChanged event handler is a multicast event handler and
' handles the CheckedChanged event for all of the CheckBox control instances.
' The statements in the event handler update the number of full or empty
' seats on the airplane.
Private Sub chkseats_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Declare a varible to store the CheckBox.
Dim chkCurrent As System.Windows.Forms.CheckBox
' Again, because sender is of type System.Object, explicitly convert
' the argument to a check box using the CType function
chkCurrent = CType(sender, System.Windows.Forms.CheckBox)
' If the check box is checked, increment the number of occupied seats
' and decrement the number of empty seats. If the check box is not checked,
' then do the reverse.
Select Case chkCurrent.Checked
Case True
mintFull += 1
mintEmpty -= 1
Case False
mintFull -= 1
mintEmpty += 1
End Select
' Display the results in the labels.
lblFull.Text = mintFull.ToString()
lblEmpty.Text = mintEmpty.ToString()
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
' Uncheck all of the check boxes by enumerating the Controls collection
' of the Panel.
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
Dim ctlCurrent As Control
Dim chkCurrent As CheckBox
' The For Each loop enumerates the Controls collection for the
' Panel rather than the form.
For Each ctlCurrent In pnlSeats.Controls
' Check that the type of the control instance is a CheckBox.
' Labels are also contained by the Panel. If the control instance
' is a CheckBox, then remove the check mark by setting the Checked property
' to False.
If TypeOf (ctlCurrent) Is System.Windows.Forms.CheckBox Then
chkCurrent = CType(ctlCurrent, System.Windows.Forms.CheckBox)
chkCurrent.Checked = False
End If
Next
lblFull.Text = ""
lblEmpty.Text = ""
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -