Custom transparent label becomes disfigured on my custom groupbox

General Fear

Dec 22, 2012
Programming Experience
I am using VB.Net 2010.

So I have 2 problems with my custom group box. I created a custom label and a custom group box.
Problem 1) If I try to change my custom group box font to size 8, will only go to 8.25.
Problem 2) If I place a transparent label on my custom group box, whenever I make a change to the font of my group box, the label becomes "disfigured". It seems at times that the labe takes the caption from the group box and put's it on the label.

My application and DLL library are separate. I set the "specific version" to false. When ever I create a new DLL, I copy it to the directory were the application is located. I do not have "option Strict On". When I first place the label into the group box it's fine. It's when I make a change and copy a new DLL to the application, for example, change the font size from 8 to 12, that I get a strange result on transparent labels.

My question is why does this happen? Below is my code:

Public Class Test
Inherits GroupBox
Dim myFont As New Font("MS Sans Serif", 8, FontStyle.Regular, GraphicsUnit.Point, Nothing)
Private _borderColor As Color
Public Sub New()
Me._borderColor = Color.Black
End Sub
Public Property BorderColor() As Color
Return Me._borderColor
End Get
Set(ByVal value As Color)
Me._borderColor = value
End Set
End Property
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
Dim tSize As SizeF = e.Graphics.MeasureString(Me.Text, myFont, Integer.MaxValue, StringFormat.GenericTypographic)
Dim borderRect As Rectangle = e.ClipRectangle
borderRect.Y = (borderRect.Y + (tSize.Height / 2))
borderRect.Height = (borderRect.Height - (tSize.Height / 2))
ControlPaint.DrawBorder(e.Graphics, borderRect, Me._borderColor, ButtonBorderStyle.Solid)
Dim textRect As RectangleF = e.ClipRectangle
textRect.X = (textRect.X + 6)
textRect.Width = tSize.Width
textRect.Height = tSize.Height
e.Graphics.FillRectangle(New SolidBrush(Me.BackColor), textRect)
e.Graphics.DrawString(Me.Text, myFont, New SolidBrush(Me.ForeColor), textRect, StringFormat.GenericTypographic)
End Sub
End Class
Public Class clsLabel
Inherits Label
Public Sub New()
Me.Font = New Font("MS Sans Serif", 8, FontStyle.Regular, GraphicsUnit.Point, Nothing)
End Sub
Public Enum enuLabelBackGroundColor
TransparentBackGround = 0
WhiteBackGround = 1
End Enum
Private MyBackGroundColor As enuLabelBackGroundColor
Public Property myBackGroundColor As enuLabelBackGroundColor
Return MyBackGroundColor
End Get
Set(value As enuLabelBackGroundColor)
MyBackGroundColor = value
Select Case value
Case enuLabelBackGroundColor.WhiteBackGround
MyBase.BackColor = Color.White
Case Else
MyBase.BackColor = Color.Transparent
End Select
End Set
End Property
End Class
Top Bottom