Private mblnHighlight As Boolean = True
Private mclrHighlight As Color = SystemColors.Highlight
Private mclrBorder As Color = SystemColors.ControlDark
Protected Overrides Sub OnMouseEnter(ByVal e As System.EventArgs)
MyBase.OnMouseEnter(e)
If mblnHighlight Then Invalidate()
End Sub
Protected Overrides Sub OnMouseLeave(ByVal e As System.EventArgs)
MyBase.OnMouseLeave(e)
If mblnHighlight Then Invalidate()
End Sub
Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)
MyBase.OnLostFocus(e)
If mblnHighlight Then Invalidate()
End Sub
Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)
MyBase.OnGotFocus(e)
If mblnHighlight Then Invalidate()
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
If m.Msg <> Win32API.WM_PAINT Then Return
Dim wrec As Win32API.RECT
Win32API.GetWindowRect(Handle, wrec)
Dim recF As New RectangleF(0.0F, 0.0F, wrec.Right - wrec.Left, wrec.Bottom - wrec.Top)
Dim hDc As IntPtr = Win32API.GetWindowDC(Handle)
With Graphics.FromHdc(hDc)
Dim pen As Pen
Dim blnHighlight As Boolean = Not DesignMode AndAlso mblnHighlight AndAlso (Focused OrElse ClientRectangle.Contains(PointToClient(MousePosition)))
If Me.ReadOnly OrElse Not Enabled Then
.FillRectangle(SystemBrushes.Window, recF)
If Text <> String.Empty Then
Dim sf As New StringFormat
If Not Multiline AndAlso AutoSize Then sf.LineAlignment = StringAlignment.Center
Select Case TextAlign
Case HorizontalAlignment.Center
sf.Alignment = StringAlignment.Center
Case HorizontalAlignment.Right
sf.Alignment = StringAlignment.Far
End Select
Dim strText As String
If Multiline OrElse PasswordChar = Char.MinValue Then
strText = Text
Else
strText = New String(PasswordChar, Text.Length)
End If
If Me.ReadOnly AndAlso Enabled Then
Dim brush As New SolidBrush(ForeColor)
.DrawString(strText, Font, brush, recF, sf)
brush.Dispose()
If blnHighlight Then
pen = New Pen(mclrHighlight)
Else
pen = New Pen(mclrBorder)
End If
Else
.DrawString(strText, Font, SystemBrushes.ControlDark, recF, sf)
pen = New Pen(mclrBorder)
End If
sf.Dispose()
Else
pen = New Pen(mclrBorder)
End If
Else
pen = New Pen(SystemBrushes.Window)
.DrawRectangle(pen, 1.0F, 1.0F, recF.Width - 3.0F, recF.Height - 3.0F)
pen.Dispose()
If blnHighlight Then
pen = New Pen(mclrHighlight)
Else
pen = New Pen(mclrBorder)
End If
End If
.DrawRectangle(pen, 0.0F, 0.0F, recF.Width - 1.0F, recF.Height - 1.0F)
pen.Dispose()
.Dispose()
End With
Win32API.ReleaseDC(Handle, hDc)
End Sub
<DefaultValue(True), Category("Behavior"), Description("Indicates whether the control will have its border highlighted " & _
"when it receives focus or the mouse pointer enters its client rectangle. The default value is True.")> _
Public Property HighlightBorder() As Boolean
Get
Return mblnHighlight
End Get
Set(ByVal Value As Boolean)
If Value = mblnHighlight Then Return
mblnHighlight = Value
If Not DesignMode Then Invalidate()
End Set
End Property
<Category("Appearance"), Description("The color of the control's border when it receives focus or the mouse pointer enters its client rectangle.")> _
Public Property HighlightColor() As Color
Get
Return mclrHighlight
End Get
Set(ByVal Value As Color)
If Value.Equals(mclrHighlight) Then Return
mclrHighlight = Value
If Not DesignMode AndAlso mblnHighlight Then Invalidate()
End Set
End Property
<EditorBrowsable(EditorBrowsableState.Never)> _
Public Function ShouldSerializeHighlightColor() As Boolean
Return Not mclrHighlight.Equals(SystemColors.Highlight)
End Function
<Category("Appearance"), Description("The color of the control's border.")> _
Public Property BorderColor() As Color
Get
Return mclrBorder
End Get
Set(ByVal Value As Color)
If Value.Equals(mclrBorder) Then Return
mclrBorder = Value
Invalidate()
End Set
End Property
<EditorBrowsable(EditorBrowsableState.Never)> _
Public Function ShouldSerializeBorderColor() As Boolean
Return Not mclrBorder.Equals(SystemColors.ControlDark)
End Function
<Browsable(False)> _
Public Shadows ReadOnly Property BorderStyle() As BorderStyle
Get
Return MyBase.BorderStyle
End Get
End Property