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
Loading
Danatas GerviPosted Oct 22, 2009, 9:32 AM
If you use event Mouse Move – it happens many time at second, so it will be slow.
Or try to use MoseEnter event, or add class-level variable- something bool pictureMouseHover, use it as flag, and it will help you to reload the picture every mouse move iteration.
Giles PapworthPosted Oct 22, 2009, 10:03 AM
The on mouse enter has significantly improoved the performance to exactly what i want, the change is instanaeous! Brillieant, thanks for that
Giles PapworthPosted Oct 22, 2009, 9:05 AM
jingePosted Oct 22, 2009, 8:03 AM
It's hard to describe. If you trust me, send the control to me, and see if I can optimized it for you.