mardi 25 mars 2014

Slow Paints On Panel Controls


Vote count:

0




I have created a custom class that uses an inherited panel, a picturebox and two labels that act as "icons" on a form for users to click and navigate throughout an application. I have done this because it gives a better graphical impression and is more customizable than just a button alone.


I have included a class to draw rounded rectangles from the following codeproject (they draw over the panel to make the panel look like it has rounded corners): http://ift.tt/1hns067


In regards to painting, I have wired my MouseEnter and MouseLeave event to toggle a boolean and then call me.invalidate() to redraw the panel background based on the boolean set by the event. My code to redraw looks like:



If mouseoverBool Then 'class variable mouseoverBool set by mouseenter/mouseleave to true/false

Dim g As Graphics = e.Graphics
g.SmoothingMode = SmoothingMode.AntiAlias
Dim brush As New LinearGradientBrush(New Point(Me.Width / 2, 0), New Point(Me.Width / 2, Me.Height), Color.LightSteelBlue, Color.LightBlue)
g.FillRoundedRectangle(brush, 0, 0, Me.Width - 1, Me.Height, 10)
g.FillRoundedRectangle(New SolidBrush(Color.FromArgb(100, 118, 173, 218)), 0, 0, Me.Width, Me.Height, 10)
g.DrawRoundedRectangle(New Pen(ControlPaint.Light(SystemColors.InactiveBorder, 0.0F)), 0, 0, Me.Width - 1, Me.Height - 1, 10)

Else

Dim g As Graphics = e.Graphics
g.SmoothingMode = SmoothingMode.AntiAlias
Dim brush As New LinearGradientBrush(New Point(Me.Width / 2, 0), New Point(Me.Width / 2, Me.Height), SystemColors.GradientInactiveCaption, ControlPaint.Dark(SystemColors.GradientActiveCaption, 0.5F))
g.FillRoundedRectangle(brush, 0, 0, Me.Width - 1, Me.Height, 10)
g.FillRoundedRectangle(New SolidBrush(Color.FromArgb(100, 118, 173, 218)), 0, 0, Me.Width, Me.Height, 10)
g.DrawRoundedRectangle(New Pen(ControlPaint.Light(SystemColors.InactiveBorder, 0.0F)), 0, 0, Me.Width - 1, Me.Height - 1, 10)

End If

End Sub


The problem occuring is that the labels and picturebox inside the panel (all controls set to transparent background) are slow to refresh their backgrounds the first time any of the custom "icon" panels paint the background. The panel paints, then like half a second later, the backgrounds on the labels and picturebox finally updates. I assume that this is occuring because calling .invalidate() forces the custom panel to repaint, and then subsequently all the controls thereafter. I am after a 'seamless' paint where the entire control paints at once, including the labels and picturebox. How should I be attempting to achieve this? Note the example above is VB, but I have tagged C# as I feel an answer in that language will do just as well.



asked 47 secs ago






Aucun commentaire:

Enregistrer un commentaire