, ComboBox ( ). . boolean, , , . OnDrawItem. , ( ) , . OnDropDown DropDownHeight = 1 (0 ), - , . , , 1 . DrawMode OwnerDrawFixed New, OnDrawItem.
reset DropDownHeight, , , - , , , , ; combobox , .
, DrawMode Normal ONLY OnDropDown, OnDrawMethod , ( ).
Public Class simpleCombo
Inherits ComboBox
Private _myCondition As Boolean = False
Public Property myCondition() As Boolean
Get
Return _myCondition
End Get
Set(ByVal value As Boolean)
_myCondition = value
End Set
End Property
Protected Overrides Sub OnDropDown(ByVal e As System.EventArgs)
If _myCondition Then
Me.DropDownHeight = 1
Else
Me.DropDownHeight = 200 //some arbitrarily large value
End If
MyBase.OnDropDown(e)
End Sub
Protected Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
If _myCondition Then
Return
Else
MyBase.OnDrawItem(e)
e.DrawBackground()
e.Graphics.DrawString(Me.Items(e.Index), Me.Font, New SolidBrush(Me.ForeColor), e.Bounds)
e.DrawFocusRectangle()
End If
End Sub
Public Sub New()
Me.DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
End Sub
End Class