How do you create a transparent label on a gradient colored form?
-
Hi, I am trying to create a form with a gradient backcolor with labels on it. I get the gradient back color of the form by overiding the onpaint event of the form. However when I put a label with color.transparant on the form I just get the backcolor of the form, system grey. I found a coulpe of aricles about gradien labels, however then you get the problem that the gradient of the label doesn't match the gradient of the form. Is there a way to get some labels on a form that at least look transparent? Thanks in Advance DJ Think, try, think, think, try, think, think, think, try, ASK, think, try, advance on step and start over...
-
Hi, I am trying to create a form with a gradient backcolor with labels on it. I get the gradient back color of the form by overiding the onpaint event of the form. However when I put a label with color.transparant on the form I just get the backcolor of the form, system grey. I found a coulpe of aricles about gradien labels, however then you get the problem that the gradient of the label doesn't match the gradient of the form. Is there a way to get some labels on a form that at least look transparent? Thanks in Advance DJ Think, try, think, think, try, think, think, think, try, ASK, think, try, advance on step and start over...
You new to create your own custom label which inherits from the .Net Label and allows Transparent Back Colours. Here is the simplest version of such a control.
Public Class CustomLabel : Inherits Label
Public Sub New() MyBase.New() Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True) Me.BackColor = Color.Transparent End Sub
End Class
Myself, I have a much more complex label I have created that supports TextElipsis, AutoHeight and so on. If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850)
-
You new to create your own custom label which inherits from the .Net Label and allows Transparent Back Colours. Here is the simplest version of such a control.
Public Class CustomLabel : Inherits Label
Public Sub New() MyBase.New() Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True) Me.BackColor = Color.Transparent End Sub
End Class
Myself, I have a much more complex label I have created that supports TextElipsis, AutoHeight and so on. If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850)
Hi, Unfortunately this doesn't quite do the trick. With the backcolor being transparent, you get the backcolor of the form. However I am overriding the onpaint event of the form to create a gradient background (see code) Any other suggestions? Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim g As Graphics = Me.CreateGraphics Dim myBrush As New LinearGradientBrush(ClientRectangle, Color.WhiteSmoke, _ Color.LimeGreen, LinearGradientMode.Horizontal) g.FillRectangle(myBrush, ClientRectangle) MyBase.OnPaint(e) End Sub thanks DJ Think, try, think, think, try, think, think, think, try, ASK, think, try, advance on step and start over...
-
Hi, Unfortunately this doesn't quite do the trick. With the backcolor being transparent, you get the backcolor of the form. However I am overriding the onpaint event of the form to create a gradient background (see code) Any other suggestions? Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) Dim g As Graphics = Me.CreateGraphics Dim myBrush As New LinearGradientBrush(ClientRectangle, Color.WhiteSmoke, _ Color.LimeGreen, LinearGradientMode.Horizontal) g.FillRectangle(myBrush, ClientRectangle) MyBase.OnPaint(e) End Sub thanks DJ Think, try, think, think, try, think, think, think, try, ASK, think, try, advance on step and start over...
Odd... I have included the entire code of my test form here. When I run it I get the gradient applied uniformly even behind the label.
Imports System.Reflection
Public Class Form1
Inherits System.Windows.Forms.Form#Region " Windows Form Designer generated code "
Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As CustomLabel Private Sub InitializeComponent() Me.Label1 = New CustomLabel Me.SuspendLayout() ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(136, 128) Me.Label1.Name = "Label1" Me.Label1.TabIndex = 0 Me.Label1.Text = "Label1" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub
#End Region
Public Shared Sub main() Application.EnableVisualStyles() Application.DoEvents() Application.Run(New Form1) End Sub Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e) Dim brush As New Drawing2D.LinearGradientBrush(Me.ClientRectangle, Color.Azure, Color.DarkGreen, Drawing2D.LinearGradientMode.BackwardDiagonal) e.Graphics.FillRectangle(brush, Me.ClientRectangle) brush.Dispose() End Sub
End Class
Public Class CustomLabel : Inherits Label
Public Sub New() MyBase.New() Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)
-
Odd... I have included the entire code of my test form here. When I run it I get the gradient applied uniformly even behind the label.
Imports System.Reflection
Public Class Form1
Inherits System.Windows.Forms.Form#Region " Windows Form Designer generated code "
Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Label1 As CustomLabel Private Sub InitializeComponent() Me.Label1 = New CustomLabel Me.SuspendLayout() ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(136, 128) Me.Label1.Name = "Label1" Me.Label1.TabIndex = 0 Me.Label1.Text = "Label1" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 266) Me.Controls.Add(Me.Label1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub
#End Region
Public Shared Sub main() Application.EnableVisualStyles() Application.DoEvents() Application.Run(New Form1) End Sub Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(e) Dim brush As New Drawing2D.LinearGradientBrush(Me.ClientRectangle, Color.Azure, Color.DarkGreen, Drawing2D.LinearGradientMode.BackwardDiagonal) e.Graphics.FillRectangle(brush, Me.ClientRectangle) brush.Dispose() End Sub
End Class
Public Class CustomLabel : Inherits Label
Public Sub New() MyBase.New() Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True)