I have a label with text "UserName" in foreground color as white and the form is on a sky-blue color. I would like to add a black border NOT to the label itself, but to the text inside of it.
Is this possible?
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
btnLogin.Enabled = False
centrarVentana(Me)
lblNombreUsuario.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
End Sub
The code obviously is just for show,since it does not do what I want.
Edit FINAL : Thanks so much everybody. It finally worked! I am leaving the code here so everybody can re use. Once you understand it its actually really easy.
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(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
NOTE : This question is not an exact duplicate of Setting a Font with outline Color in C# since I am on Visual Basic and had to do code changes for this to work correctly.