AlexCode Posted January 14, 2005 Posted January 14, 2005 Hi! I have a set of inherited Windows.Forms controls that I have anhanced. One of those enhancements is the possibility of display a gradient background. No problem with the painting, the problem is that, for example, on the Label control, the background doesn't refresh if another window passes over it or even if the control is resized... My painting code is: Protected Overrides Sub OnPaintBackground(ByVal pevent As System.Windows.Forms.PaintEventArgs) MyBase.OnPaint(pevent) If (Not _BackColor2.IsEmpty) OrElse (Not FillType = Core.Enums.eFillType.OneColor_A) Then Dim gr1, gr2 As System.Drawing.Drawing2D.LinearGradientBrush Select Case FillType Case Core.Enums.eFillType.Vertical_AB gr1 = New System.Drawing.Drawing2D.LinearGradientBrush( _ New Point(0, 0), New Point(0, pevent.ClipRectangle.Height), _ Me.BackColor, Me.BackColor2) pevent.Graphics.FillRectangle(gr1, pevent.ClipRectangle) 'Case Core.Enums.eFillType.Vertical_ABA ' ... all other gradient drawing is similar ... End Select Else MyBase.OnPaintBackground(pevent) End If End Sub Note that: 1- The text is allways well drawn (so the Paint event is called properlly) 2- BackColor2 is a property representing the 2nd gradient color 3- Core.Enums.eFillType.Vertical_AB and all the similar are part of an Enumeration that represents the kind of gradient painting, ie. Vertical_AB represents a vertical gradient from color A to color B. Thanks! Alex Quote Software bugs are impossible to detect by anybody except the end user.
Administrators PlausiblyDamp Posted January 14, 2005 Administrators Posted January 14, 2005 Is it redrawing the gradient but incorrectly? If so it is probably because you are using the clip rectangle to calculate the gradient as well as which part to redraw. Try changing the code like so gr1 = New System.Drawing.Drawing2D.LinearGradientBrush( _ New Point(0, 0), New Point(0, pevent.ClipRectangle.Height), _ Me.BackColor, Me.BackColor2) 'change to gr1 = New System.Drawing.Drawing2D.LinearGradientBrush( _ New Point(0, 0), New Point(Me.Height, Me.Width), _ Me.BackColor, Me._BackColor2) and see if that helps. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
AlexCode Posted January 14, 2005 Author Posted January 14, 2005 Damn stupid thing... The clip rectangle only represents the invalidated area right? Damn... Thanks... it works perfectly now... Alex :p Quote Software bugs are impossible to detect by anybody except the end user.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.