Hello All,
I have been struggling with a little project that needs a label to contain text with an outline aka stroke.
The Text is white and the background in teal. I would like to be able to add a black stroke to the text contained in a Label
I came across lots of interesting code and have figured out how to create just outline text but I need to have the text white with a black outline.
The code I have been trying to use to achieve this is as follows
This isn't my code but it does seem to indicate that it should do as I want.Code:Imports System.Drawing.Drawing2D Public Class BorderLabel Inherits Label Public outline_color As Color = Color.Black Public border_thickness As Integer = 5 Public Sub New() MyBase.New End Sub Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) e.Graphics.FillRectangle(New SolidBrush(BackColor), ClientRectangle) Dim gp As GraphicsPath = New GraphicsPath Dim outline As Pen = New Pen(Me.outline_color, Me.border_thickness) Dim sf As StringFormat = New StringFormat Dim foreBrush As Brush = New SolidBrush(ForeColor) gp.AddString(GV.Text, Font.FontFamily, CType(Font.Style, Integer), Font.Size, ClientRectangle, sf) e.Graphics.ScaleTransform(1.3!, 1.35!) e.Graphics.SmoothingMode = SmoothingMode.HighQuality e.Graphics.DrawPath(outline, gp) e.Graphics.FillPath(foreBrush, gp) End Sub End Class
I created a new project to test this and just using the defaults
Form1
and a label named BorderLabel1 with some text "Test TEXT"
So this is where I fall down. I cannot get it to work at all and am hoping that someone might be able to point out where I am going wrong.
I simply want to use a label with the added functionality of being able to display the text with a border where the text color is defined, the border color is defined and the border width is defined, along with all the normal attributes associated with the control
I thought that using a label named BorderLabel1 would distinguish the it from the normal Label control.
I am looking forward to your advice and guidance
Regards,
Antony.




Reply With Quote
