我有2个组合框,我试图用作下拉列表,我希望能够单击一个按钮来保存这些组合框的选定值而不使用全局变量,但我无法访问它们的值button.click事件。而且我不确定如何使用标签来做到这一点。 (我试过,它不起作用,不确定是不是因为我错过了某些东西或者它们没有初始值)。
我如何能够引用这些组合框的内容,以便我可以保存它们的值?
这是我的代码:
Private Sub Options_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim WindowChoice, ScreenChoice As New ComboBox
Dim SaveChanges As New Button
ScreenSizes(0) = "640x360"
ScreenSizes(1) = "960x540"
ScreenSizes(2) = "1024x576"
ScreenSizes(3) = "1280x720"
ScreenSizes(4) = "1600x900"
ScreenSizes(5) = "1920x1080"
WindowChoice.Items.Add("Windowed")
WindowChoice.Items.Add("Fullscreen")
For i As Integer = 0 To ScreenSizes.length - 1
ScreenChoice.Items.Add(ScreenSizes(i))
Next
MainMenu.AddObject(SaveChanges, _
(Me.Width / 2 + SaveChanges.Width / 2), _
(Me.Height / 2 + 4 * SaveChanges.Height), _
"Save Changes", _
Me) 'These add the object at a specified postion
MainMenu.AddObject(WindowChoice, _
(Me.Width / 2 + WindowChoice.Width / 2), _
(Me.Height / 2 - 2 * WindowChoice.Height), _
"", _
Me)
MainMenu.AddObject(ScreenChoice, _
(Me.Width / 2 + ScreenChoice.Width / 2), _
(Me.Height / 2), _
"", _
Me)
AddHandler SaveChanges.Click, AddressOf SaveChanges_click
SaveChanges.Tag = Str(WindowChoice.SelectedItem(0)) & Str(ScreenChoice.SelectedItem) 'this line currently does not work, but even if it were able to assign a value, it would only do so before an option has been selected
End Sub
Private Sub SaveChanges_click(ByVal sender As Object, ByVal e As EventArgs)
If sender.Tag(0) = "W" Then
MainMenu.Windowed = True
ElseIf sender.Tag(0) = "F" Then
MainMenu.Windowed = False
End If
Dim res As String = ""
For i As Integer = 1 To sender.tag.length - 1
res &= sender.tag(i)
Next
MainMenu.Res = res
End Sub