Files
RecordOrganizer/app/DD-Record-Organiser/ClassCustomComboBox.vb
2016-04-14 17:09:57 +02:00

52 lines
1.7 KiB
VB.net

Public Class CustomComboBox
Inherits Windows.Forms.ComboBox
Public Sub New()
MyBase.New()
DrawMode = Windows.Forms.DrawMode.OwnerDrawFixed
End Sub
Protected Overrides Sub OnEnabledChanged(e As EventArgs)
'MyBase.OnEnabledChanged(e)
If Me.Enabled Then
Me.DropDownStyle = ComboBoxStyle.DropDown
Else
Me.DropDownStyle = ComboBoxStyle.DropDownList
End If
End Sub
Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs)
Dim g As System.Drawing.Graphics = e.Graphics
Dim rect As Rectangle = e.Bounds
If e.Index >= 0 Then
Dim label As String = Me.Items(e.Index).ToString()
If e.State = (DrawItemState.Disabled Or DrawItemState.NoAccelerator Or DrawItemState.NoFocusRect Or DrawItemState.ComboBoxEdit) Then
' DISABLED STATE
g.FillRectangle(New SolidBrush(System.Drawing.SystemColors.Info), rect)
g.DrawString(label, e.Font, Brushes.Black, rect)
e.DrawFocusRectangle()
ElseIf (e.State = (DrawItemState.NoAccelerator Or DrawItemState.NoFocusRect)) Then
' ITEMS NOT IN FOCUS
g.FillRectangle(New SolidBrush(Color.White), rect)
g.DrawString(label, e.Font, Brushes.Black, rect)
e.DrawFocusRectangle()
Else
' ITEMS IN FOCUS
g.FillRectangle(New SolidBrush(System.Drawing.SystemColors.Highlight), rect)
g.DrawString(label, e.Font, Brushes.White, rect)
e.DrawFocusRectangle()
End If
End If
g.Dispose()
End Sub
End Class