Creating a class that inherits off of label and displays text with a color
outline: The whole class is below (it's small). The outlining works great -
the only problem is that the graphicspath created by the AddString is too
small. I've put down a 36 point label control at the bottom of the form for
comparison, and the result of the text below is about half the size. Or, if
you uncomment the last line (which simply draws the text of the label, it's
also the "correct" size".
Any idea?
matt tag
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Public Class OutlineLabel
Inherits Label
Property OutLineWidth() As Integer ...
Property OutLineColor() As Color..
Private Sub OutlineLabel_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim gpFont As New GraphicsPath()
Dim gpBig As GraphicsPath
Dim aPen As Pen
'draw backgroud
e.Graphics.FillRectangle(New SolidBrush(Me.BackColor),
Me.ClientRectangle)
e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias
gpFont.AddString(Me.Text, Me.Font.FontFamily, _
CInt(Me.Font.Style), Me.Font.Size, _
New PointF(0, 0), System.Drawing.StringFormat.GenericDefault)
'clone the graphicspath, and widen it by the width specified
gpBig = gpFont.Clone
aPen = New Pen(Color.Black, fOutlineWidth)
With aPen
.StartCap = LineCap.Round
.EndCap = LineCap.Round
.LineJoin = LineJoin.Round
End With
gpBig.Widen(aPen)
'draw the 2 graphicspath
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
e.Graphics.FillPath(New SolidBrush(fOutlineColor), gpBig)
e.Graphics.FillPath(New SolidBrush(Me.ForeColor), gpFont)
'e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush
(Me.ForeColor), 0, 0)
End Sub
End Class
You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.