1

我正在运行时创建 ToolStripMenuItem 的 DropDownItems。

    Me.mnuExtrasSecondaryLCID.DropDownItems.Clear()

    Dim iCount As Integer = -1

    For Each nLang As clsLanguage In g_LCIDs
        If nLang.IsLeader Then

            iCount += 1

            Dim n As New ToolStripMenuItem
            n.Name = "mnuSecondaryLCID" & iCount.ToString()
            n.Text = nLang.Title
            n.Tag = nLang.LCID
            n.Available = True
            n.CheckOnClick = True

            Me.mnuExtrasSecondaryLCID.DropDownItems.Add(n)

            AddHandler n.Click, AddressOf Me.SecondaryLCIDClick

        End If
    Next

这工作正常。

然后,当我在运行时检查其中一个 DropDownItems 时,同一“列表”中的任何其他 DropDownItems 都会保持选中状态。相反,我只想检查一个(=最后点击的一个)。

是否有一个属性可以让我自动执行此操作,或者我是否需要通过手动取消选中所有其他 DropDropItems 来对此进行编码?

4

1 回答 1

0

You need to code it manually. When clicking on a sub menu, uncheck all other siblings:

For index = 1 To 5
    Dim subMenu = New ToolStripMenuItem(index.ToString())
    subMenu.CheckOnClick= True
    AddHandler subMenu.Click, Sub(obj, arg)
        Dim item = DirectCast(obj, ToolStripMenuItem)
        For Each sibling In item.Owner.Items.OfType(Of ToolStripMenuItem).Except({obj})
           sibling.Checked = False
        Next sibling
    End Sub
    Menu1ToolStripMenuItem.DropDownItems.Add(subMenu)
Next
于 2018-01-05T21:42:57.660 回答