我正在尝试将文本文件中的记录链接到按钮网格,以便当您单击按钮时,它会显示来自文本文件中特定行的信息。
[编辑] 这是代码
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is Button And ctrl.BackColor = Color.Gold Then
btn = DirectCast(ctrl, Button)
AddHandler btn.Click, AddressOf Me.Gold_Click
ElseIf TypeOf ctrl Is Button And ctrl.BackColor = Color.Silver Then
btn = DirectCast(ctrl, Button)
AddHandler btn.Click, AddressOf Me.Silver_CLick
ElseIf TypeOf ctrl Is Button And ctrl.BackColor = Color.DarkOrange Then
btn = DirectCast(ctrl, Button)
AddHandler btn.Click, AddressOf Me.Bronze_CLick
End If
Next
Using sr As New IO.StreamReader("seatingplan.txt")
While Not sr.EndOfStream
arr = sr.ReadLine.Split(vbTab)
SeatArray(x, 0) = arr(0)
SeatArray(x, 1) = arr(1)
SeatArray(x, 2) = arr(2)
SeatArray(x, 3) = arr(3)
Temp += arr(2)
x += 1
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is Button And ctrl.Text <> "Pay Now" Then
'btn = DirectCast(ctrl, Button)
End If
Next
End While
End Using
从评论中添加 文本文件中的四个元素是 SeatID、SeatType、SeatPrice 和 SeatAvailability。
Sub Gold_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
SeatInfo.Show()
SeatInfo.lblclass.Text = "Gold"
End Sub
“黄金”指的是我已经完成的程序的不同部分。
公共类 SeatInfo Dim SeatTotal As Decimal = 0 Dim totalbooking As Integer = 0
Public Sub RadioButton4_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbtnadult.CheckedChanged
Dim SeatClass As String = lblclass.Text
Select Case SeatClass
Case "Gold"
SeatTotal = 30
Case Else
SeatTotal = 0
End Select
SeatTotalBox.Text = FormatCurrency(SeatTotal, 2)
End Sub
Public Sub RadioButton5_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles rbtncon.CheckedChanged
Dim SeatClass As String = lblclass.Text
Select Case SeatClass
Case "Gold"
SeatTotal = 20
Case Else
SeatTotal = 0
End Select
SeatTotalBox.Text = FormatCurrency(SeatTotal, 2)
End Sub
Public Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
totalbooking += SeatTotal
BookingScreen.lbltotalbooking.Text = FormatCurrency(totalbooking, 2)
Me.Hide()
AddHandler Button1.Click, AddressOf BookingScreen.Reserve_Click
'If Accept Booking has been pressed, set button to 'red' to signal a reserved seat.
End Sub
结束类