我有一个菜单条,可以添加/删除按钮。我希望能够获得每个按钮的高度,并将它们添加起来。这可能吗?
答案 0 :(得分: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