Ok So I'm creating a "Windows Forms Application" for some guy using C# and I want to make the UI a bit more interesting for him.
The main form looks like a big dial with custom buttons arranged on it. (I'm saying custom buttons since they are actually simple user controls I've created that have a PictureBox and a Label that enlarges when the user points it and then shrink when the mouse cursor is moved outside it. There's also an Image property which sets the PictureBox's Image and is used as the icon of the so called custom button.)
I used two timers named tmrEnlarge and tmrShrink which activate on MouseEnter and MouseLeave events respectively. Basically nothing but a couple of simple functions to increase and decrease the size of the PictureBox used in my custom control and making it look like it's zooming in...
It works just fine but the problem is, when the mouse hovers several controls at the same time, the animation slows dows (which in my opinion is normal, since timers are not the best way for doing something like I did!) I tried using threads as well but the problem's still here! :-(
What I want to know is what's the best way for doing something like this?
EDIT:
Here's the code I used for drawing the image directly on the control without using a PictureBox:
(It's just a quick version and it leaves residues after drawing the image, which is not important for me right now)
public partial class DDAnimatingLabel : UserControl
{
public Image Image { get; set; }
public DDAnimatingLabel()
{
InitializeComponent();
}
private void DDAnimatingLabel_MouseEnter(object sender, EventArgs e)
{
tmrEnlarge.Enabled = true;
}
protected override void OnPaint(PaintEventArgs e)
{
if (Image != null)
{
e.Graphics.DrawImage(this.Image, e.ClipRectangle);
}
else
base.OnPaint(e);
}
private void tmrEnlarge_Tick(object sender, EventArgs e)
{
if (Size.Width >= MaximumSize.Width)
{
tmrEnlarge.Enabled = false;
return;
}
Size s = Size;
s.Height += 4;
s.Width += 4;
Size = s;
Point p = Location;
p.X -= 2;
p.Y -= 2;
Location = p;
}
private void tmrShrink_Tick(object sender, EventArgs e)
{
if (tmrEnlarge.Enabled)
return;
if (Size.Width == MinimumSize.Width)
{
tmrShrink.Enabled = false;
return;
}
Size s = Size;
s.Height -= 4;
s.Width -= 4;
Size = s;
Point p = Location;
p.X += 2;
p.Y += 2;
Location = p;
}
private void DDAnimatingLabel_MouseLeave(object sender, EventArgs e)
{
tmrShrink.Enabled = true;
}
}