Control Repaint

Oct 22 2009 6:19 AM
Hi all,

As you may have seen from one of my previous posts, i have a control that is used for a button. It paints a graphic on the paint method of the control.

When the mouse hovers over the control, it detects this and repaints it with the relevant image for the mouse hover. However it is taking quite some time for the repaint to happen.
I have set the double buffer to true and i have tried using this.Refresh() instaed of this.Invalidate() but only seeing a marginal difference in speed.
Is there anything i can do to speed this up?

The images have already been loaded into a local bitmap and then just simply drawn in place. The code is below:

if (this.Enabled)
            {
                e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed;
                try
                {
                    switch (ControlState)
                    {
                        case ControlStateEnum.Normal:
                            e.Graphics.DrawImage(MouseNormalImage, 0, 0, Width, Height);
                            break;
                        case ControlStateEnum.Over:
                            e.Graphics.DrawImage(MouseHoverImage, 0, 0, Width, Height);
                            break;
                    }
                }
                catch { }
            }

if anyone can think of a way of speeding this up that sould be great.

Cheers


Answers (4)