Form Gradient with Controls On Top

  • Thread starter Thread starter a
  • Start date Start date
A

a

I want a form with a LinearGradient, which is easy enough. The troublke I
have is that when I place a label on top, the label obscures my fill, even
when I set the BackColor of the label to Transparent.

Using WinXP and included a Manifest File to use WindowsXP Styles.

Is this a know issue?

Kevin
 
Hi Kevin,

What value did you set to the Label.FlatStyle?
If it is System, you need change it to either of the rest 3 options, since
Transprent color is a feature simulated by winform Label control, the
default system label control doesn't support transparent.

Does it resolve your problem?
Feel free to reply this thread if you still have problem on it.
Have a nice day!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
That did not work, it was already set to STANDARD.

I have a Label with a BackColor set to Transparent on top of the form, and
this code in the form.

Any other ideas?

Kevin

Private Sub frmAbout_Paint(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim g As Graphics = Me.CreateGraphics

Dim b As New Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, _

Color.AliceBlue, Color.DimGray,
Drawing.Drawing2D.InterpolationMode.HighQualityBilinear)

g.FillRectangle(b, e.ClipRectangle)

End Sub

Private Sub frmAbout_Resize(ByVal sender As Object, _

ByVal e As System.EventArgs) Handles MyBase.Resize

Me.Invalidate()

End Sub
 
Hi Kevin,

The problem seems in your Paint event handler,
as you may hear about the transparency of label control is simulated by
repainting the parent control, so in frmAbout_Paint event handler you need
always use the Graphics object passed by PaintEventargs, since the Graphics
created by this.CreateGraphics is associated with the parent control which
has no effect on painting the label control. And the Rectangle in the
LinearGradientBrush constructor should use Form.ClientRectangle to make the
gradient consistent with the background.
Here is a revised version of the event handler, you may test it to see if
it works on your form.
<code>
Private Sub frmAbout_Paint(ByVal sender As System.Object, _

ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim b As New Drawing.Drawing2D.LinearGradientBrush(e.ClipRectangle, _
Color.AliceBlue, Color.DimGray,
LinearGradientMode.Vertical)

'I didn't see an overload definition could accept InterpolationMode, change
it
'to LinearGradientMode to make it compile though
'Drawing.Drawing2D.InterpolationMode.HighQualityBilinear)

e.Graphics.FillRectangle(b, e.ClipRectangle)
End Sub

</code>

Good Luck!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
fix a type in previous code snippet,
I tested this issue in C#, there might be some typos when translating the
test code (C#) to VB.NET.
If you have problem to make the snippet work, please feel free to let me
know.
<code>
Private Sub frmAbout_Paint(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

Dim b As New Drawing.Drawing2D.LinearGradientBrush(Me.ClientRectangle, _
Color.AliceBlue, Color.DimGray, LinearGradientMode.Vertical)

'I didn't see an overload definition could accept InterpolationMode, change
it
'to LinearGradientMode to make it compile through
'Drawing.Drawing2D.InterpolationMode.HighQualityBilinear)

e.Graphics.FillRectangle(b, e.ClipRectangle)
End Sub
</code>

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
EUREKA!

Private Sub frmAbout_Paint(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim b As New Drawing.Drawing2D.LinearGradientBrush(Me.ClientRectangle, _
Color.AliceBlue, Color.DimGray,
Drawing.Drawing2D.InterpolationMode.HighQualityBilinear)
e.Graphics.FillRectangle(b, e.ClipRectangle)
End Sub

e.Graphics worked where Me.CreateGrphics did not!
Thanks!
 
Back
Top