MephobiaHF

[Release|VB.Net] Label Shadow [Custom Shadow Color + Distanc

Oct 8th, 2012
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.67 KB | None | 0 0
  1. Imports System.ComponentModel
  2.  
  3. Public Class LabelShadow : Inherits Control
  4.  
  5.     Public _ShadowColor As Color
  6.     Public _ShadowDistance As Point
  7.  
  8.     Public Property ShadowColor As Color
  9.         Get
  10.             Return _ShadowColor
  11.         End Get
  12.         Set(ByVal value As Color)
  13.             _ShadowColor = value
  14.         End Set
  15.     End Property
  16.     Public Property ShadowDistance As Point
  17.         Get
  18.             Return _ShadowDistance
  19.         End Get
  20.         Set(ByVal value As Point)
  21.             _ShadowDistance = value
  22.         End Set
  23.     End Property
  24.  
  25.     Sub New()
  26.         MyBase.New()
  27.         SetStyle(ControlStyles.UserPaint Or ControlStyles.SupportsTransparentBackColor, True)
  28.         BackColor = DefaultBackColor
  29.         ForeColor = Color.Black
  30.         Size = New Size(145, 10)
  31.         DoubleBuffered = True
  32.         _ShadowDistance = New Point(1, 1)
  33.     End Sub
  34.  
  35.     Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  36.         Dim B As New Bitmap(Width, Height)
  37.         Dim G As Graphics = Graphics.FromImage(B)
  38.         Dim checkBoxRectangle As New Rectangle(0, 0, Height - 1, Height - 1)
  39.  
  40.         G.Clear(BackColor)
  41.         'shadow
  42.         G.DrawString(Text, Font, New SolidBrush(_ShadowColor), New Point(_ShadowDistance), New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  43.         'text
  44.         G.DrawString(Text, Font, New SolidBrush(ForeColor), New Point(0, 0), New StringFormat With {.Alignment = StringAlignment.Near, .LineAlignment = StringAlignment.Near})
  45.  
  46.         e.Graphics.DrawImage(B.Clone(), 0, 0)
  47.         G.Dispose() : B.Dispose()
  48.  
  49.     End Sub
  50.  
  51. End Class
Advertisement
Add Comment
Please, Sign In to add comment