Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Software bugs are impossible to detect by anybody except the end user.
  • Administrators
Posted

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.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Damn stupid thing...

The clip rectangle only represents the invalidated area right?

 

Damn...

 

Thanks... it works perfectly now...

 

Alex :p

Software bugs are impossible to detect by anybody except the end user.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...