【发布时间】:2011-09-26 12:00:18
【问题描述】:
有没有办法将自定义控件添加到StatusStrip 控件?
比方说,我需要一个状态栏中的多列组合框...
【问题讨论】:
-
使用 ToolStripControlHost 和 [ToolStripDesignerAvailability] 属性。
标签: .net winforms statusstrip
有没有办法将自定义控件添加到StatusStrip 控件?
比方说,我需要一个状态栏中的多列组合框...
【问题讨论】:
标签: .net winforms statusstrip
正如Hans Passant 提到的谦虚,解决方案是使用ToolStripControlHost 和ToolStripDesignerAvailability 属性。
更多详情可咨询here
【讨论】:
最简单的方法是使用 ToolStripComboBox 自己进行绘图,然后将该控件放在您的 StatusStrip 中。 ToolStripComboBox 与普通的 ComboBox 不同,因为它derives from the ToolStripControlHost。
Dim comboStatus As New ToolStripComboBox
With DirectCast(comboStatus.Control, ComboBox)
.DrawMode = DrawMode.OwnerDrawFixed
AddHandler .DrawItem, AddressOf comboStatus_DrawItem
End With
StatusStrip1.Items.Add(comboStatus)
然后你使用 DrawItem 事件:
Private Sub comboStatus_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs)
Dim comboStatus As ComboBox = sender
e.DrawBackground()
If e.Index > -1 Then
//Do you drawing.
End If
End Sub
图纸详情请见ComboBox.DrawItem Event。
【讨论】: