我有一个 VB.Net 工具条,我以编程方式向其中添加按钮。某些按钮被选中或取消选中取决于用户上次设置应用程序时它们所处的状态(来自存储在注册表中的值:
Dim OneButton As New ToolStripButton("T", Nothing, Nothing, "Thailandr")
OneButton.CheckOnClick = True
AddHandler OneButton.Click, AddressOf ClickHandlerLayers
tsLayers.Items.Add(OneButton)
If GetSetting(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath), "Settings", "ThailandSetting", False) Then
OneButton.PerformClick()
End If
OneButton = New ToolStripButton("W", Nothing, Nothing, "World")
OneButton.CheckOnClick = True
AddHandler OneButton.Click, AddressOf ClickHandlerLayers
tsLayers.Items.Add(OneButton)
If GetSetting(IO.Path.GetFileNameWithoutExtension(Application.ExecutablePath), "Settings", "WorldSetting", False) Then
OneButton.PerformClick()
End If
一切正常,除了我想在用户单击应用按钮时将按钮的值保存回注册表。我想通过循环遍历 tsLayers 工具条而不是硬编码来保存值(这是可能的,但是当我添加更多按钮时需要额外的工作)。到目前为止,我可以看到名称
' Save which background layers are to be used
For Each tb As ToolStripItem In tsLayers.Items
Debug.Print(tb.Name)
Debug.Print(tb.GetType.ToString)
Debug.Print(tb.Selected)
Debug.Print(tb.Pressed)
Next
结果是:
Thailand
System.Windows.Forms.ToolStripButton
False
False
World
System.Windows.Forms.ToolStripButton
False
False
即使在查看结果时按下/检查了其中一个按钮。我看不到任何其他可以帮助我的属性,也看不到任何我可以挖掘的收藏。
有没有办法通过遍历工具条来确定工具条中工具条按钮的检查状态?