【问题标题】:Custom control in StatusStip controlStatusStip 控件中的自定义控件
【发布时间】:2011-09-26 12:00:18
【问题描述】:

有没有办法将自定义控件添加到StatusStrip 控件?

比方说,我需要一个状态栏中的多列组合框...

【问题讨论】:

  • 使用 ToolStripControlHost 和 [ToolStripDesignerAvailability] 属性。

标签: .net winforms statusstrip


【解决方案1】:

正如Hans Passant 提到的谦虚,解决方案是使用ToolStripControlHostToolStripDesignerAvailability 属性。

更多详情可咨询here

【讨论】:

    【解决方案2】:

    最简单的方法是使用 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

    【讨论】:

    • 我们使用 Infragistics UltraCombo 敌人 2 列组合框...所以问题只是将 UltraCombo 集成到 StatusStrip...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 2015-09-07
    • 2011-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多