我有一个以编程方式添加按钮的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所有操作都很好,除了当用户单击Apply按钮时,我希望将按钮的值保存回注册表。我希望通过循环遍历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即使其中一个按钮在查看结果时被按下/检查。我看不到任何其他可以帮助我的属性,也看不到任何我可以挖掘的集合。
是否有方法通过遍历工具条来确定工具条中工具条按钮的checkState?
发布于 2013-08-29 08:35:25
将ToolStripItem转换为ToolStripButton,您将可以访问CheckState属性
If tb.GetType Is GetType(ToolStripButton) Then
Dim tbCast As ToolStripButton = DirectCast(tb, ToolStripButton)
Debug.Print(tbCast.CheckState)
End Ifhttps://stackoverflow.com/questions/18504164
复制相似问题