首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从ToolStripButton循环确定CheckState

从ToolStripButton循环确定CheckState
EN

Stack Overflow用户
提问于 2013-08-29 06:56:55
回答 1查看 857关注 0票数 0

我有一个以编程方式添加按钮的VB.Net工具条。根据用户上次设置应用程序时保留的状态(来自存储在注册表中的值),一些按钮被选中或未选中:

代码语言:javascript
复制
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工具条来保存这些值,而不是硬编码(这是可能的,但当我添加更多按钮时,这是额外的工作)。到目前为止,我可以看到名字

代码语言:javascript
复制
   ' 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

结果如下:

代码语言:javascript
复制
Thailand
System.Windows.Forms.ToolStripButton
False
False

World
System.Windows.Forms.ToolStripButton
False
False

即使其中一个按钮在查看结果时被按下/检查。我看不到任何其他可以帮助我的属性,也看不到任何我可以挖掘的集合。

是否有方法通过遍历工具条来确定工具条中工具条按钮的checkState?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-29 08:35:25

ToolStripItem转换为ToolStripButton,您将可以访问CheckState属性

代码语言:javascript
复制
        If tb.GetType Is GetType(ToolStripButton) Then
            Dim tbCast As ToolStripButton = DirectCast(tb, ToolStripButton)
            Debug.Print(tbCast.CheckState)
        End If
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18504164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档