1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| Imports System.ComponentModel
Imports System.Windows.Forms.VisualStyles
Partial Public Class RadioButtonList
Private s As Size
Protected Overrides Sub OnDrawItem(ByVal e As DrawItemEventArgs)
Dim text = If((Items.Count > 0), GetItemText(Items(e.Index)), Name)
Dim r As Rectangle = e.Bounds
Dim p As Point
Dim flags = TextFormatFlags.[Default] Or TextFormatFlags.NoPrefix
Dim selected = (e.State And DrawItemState.Selected) = DrawItemState.Selected
Dim state = If(selected, (If(Enabled, RadioButtonState.CheckedNormal, RadioButtonState.CheckedDisabled)), (If(Enabled, RadioButtonState.UncheckedNormal, RadioButtonState.UncheckedDisabled)))
If RightToLeft = System.Windows.Forms.RightToLeft.Yes Then
p = New Point(r.Right - r.Height + (ItemHeight - s.Width) / 2, r.Top + (ItemHeight - s.Height) / 2)
r = New Rectangle(r.Left, r.Top, r.Width - r.Height, r.Height)
flags = flags Or TextFormatFlags.RightToLeft Or TextFormatFlags.Right
Else
p = New Point(r.Left + (ItemHeight - s.Width) / 2, r.Top + (ItemHeight - s.Height) / 2)
r = New Rectangle(r.Left + r.Height, r.Top, r.Width - r.Height, r.Height)
End If
Dim bc = If(selected, (If(Enabled, SystemColors.Highlight, SystemColors.InactiveBorder)), BackColor)
Dim fc = If(selected, (If(Enabled, SystemColors.HighlightText, SystemColors.GrayText)), ForeColor)
Using b = New SolidBrush(bc)
e.Graphics.FillRectangle(b, e.Bounds)
End Using
RadioButtonRenderer.DrawRadioButton(e.Graphics, p, state)
TextRenderer.DrawText(e.Graphics, text, Font, r, fc, bc, flags)
e.DrawFocusRectangle()
MyBase.OnDrawItem(e)
End Sub
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public Overrides Property SelectionMode As SelectionMode
Get
Return System.Windows.Forms.SelectionMode.One
End Get
Set(ByVal value As SelectionMode)
End Set
End Property
<Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public Overrides Property ItemHeight As Integer
Get
Return (Me.Font.Height + 2)
End Get
Set(ByVal value As Integer)
End Set
End Property
<EditorBrowsable(EditorBrowsableState.Never), Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)>
Public Overrides Property DrawMode As DrawMode
Get
Return MyBase.DrawMode
End Get
Set(ByVal value As DrawMode)
MyBase.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed
End Set
End Property
End Class |