我有一个菜单条,可以添加/删除按钮。我希望能够获得每个单独按钮的高度,并将它们相加。这可能吗?
问问题
462 次
1 回答
0
消息框给出了 MenuStrip1 中每个 ToolStripItem 的 Text,然后是 ToolStripItem 的高度(在括号中)。消息框的底部包含 MenuStrip1 中所有控件的总高度。
这是你想要的?
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim total As Integer
Dim menues As New List(Of ToolStripItem)
For Each t As ToolStripItem In MenuStrip1.Items
GetMenues(t, menues)
Next
Dim msg As New StringBuilder
For Each t As ToolStripItem In menues
msg.Append(t.Text)
msg.Append(" (")
msg.Append(t.Height)
msg.AppendLine(")")
total += t.Height
Next
msg.AppendLine("")
msg.AppendLine("")
msg.Append("Total Height: ")
msg.Append(total)
MessageBox.Show(msg.ToString)
End Sub
Public Sub GetMenues(ByVal Current As ToolStripItem, ByRef menues As List(Of ToolStripItem))
menues.Add(Current)
If TypeOf (Current) Is ToolStripMenuItem Then
For Each menu As ToolStripItem In DirectCast(Current, ToolStripMenuItem).DropDownItems
GetMenues(menu, menues)
Next
End If
End Sub
于 2013-06-29T00:11:56.253 回答