code_junkie

Transparent control backgrounds on a VB.NET gradient filled form

Nov 14th, 2011
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. Public Class TransparentLabel
  2. Inherits Label
  3.  
  4. Public Sub New()
  5. Me.SetStyle(ControlStyles.Opaque, True)
  6. Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, False)
  7. End Sub
  8.  
  9. Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
  10. Get
  11. Dim cp As CreateParams = MyBase.CreateParams
  12. cp.ExStyle = cp.ExStyle Or &H20 ' Turn on WS_EX_TRANSPARENT
  13. Return cp
  14. End Get
  15. End Property
  16. End Class
  17.  
  18. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
  19.  
  20. Dim formGraphics As Graphics = e.Graphics
  21. Dim gradientBrush As New LinearGradientBrush(New Point(0, Height), New Point(0, 0), Me.AppSettings.FormGradiantFrom, Me.AppSettings.FormGradiantTo)
  22.  
  23. formGraphics.FillRectangle(gradientBrush, ClientRectangle)
  24.  
  25. End Sub
  26.  
  27. SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or _
  28. ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
Add Comment
Please, Sign In to add comment