Hi Gonzalo DÃaz,
Based on your description and the action script you provided with, I find a similar implementation below:
Animation.cs, the file includes the animation logic:
internal class Animation
{
/// <summary>
/// Initialization
/// </summary>
/// <param name="form">the animation form</param>
/// <param name="timeInterval">the ticket amount for each move</param>
public Animation(Form form, int timeInterval)
{
_hx = form.ClientRectangle.Width / 2 - 20;
_r = 300;
form.MouseMove += new MouseEventHandler(form_MouseMove);
_timer.Interval = timeInterval;
_timer.Tick += new EventHandler(_timer_Tick);
}
/// <summary>
/// Add a control , save its information and initiallize it
/// </summary>
/// <param name="ctrl"></param>
public void AddControl(Control ctrl)
{
ControlState ctrlState = new ControlState();
ctrlState.Control = ctrl;
ctrlState.StartLocation = ctrl.Location;
ctrlState.StartSize = ctrl.Size;
ctrlState.StartColor = ctrl.ForeColor;
//Stop moving when the mouse is on the control and change the size of the control to alert user.
ctrl.MouseEnter += new EventHandler(ctrl_MouseEnter);
ctrl.MouseLeave += new EventHandler(ctrl_MouseLeave);
this._controls.Add(ctrlState);
}
private void ctrl_MouseEnter(object sender, EventArgs e)
{
_stopped = true;
Control ctrl = sender as Control;
ctrl.Size = Size.Round(new SizeF(ctrl.Width * FONT_CHANGE_MOUSE_ON, ctrl.Height * FONT_CHANGE_MOUSE_ON));
ctrl.Font = new Font(ctrl.Font.FontFamily, ctrl.Height * FONT_BUTTON_WIDTH__RATE);
}
private void ctrl_MouseLeave(object sender, EventArgs e)
{
_stopped = false;
Control ctrl = sender as Control;
ctrl.Size = Size.Round(new SizeF(ctrl.Width / FONT_CHANGE_MOUSE_ON, ctrl.Height / FONT_CHANGE_MOUSE_ON));
ctrl.Font = new Font(ctrl.Font.FontFamily, ctrl.Height * FONT_BUTTON_WIDTH__RATE);
}
/// <summary>
/// Start the animation.
/// </summary>
public void Start()
{
float angleUnit = (float)(2 * Math.PI / _controls.Count);
float initAngle = 0.0f;
foreach (ControlState ctrl in _controls)
{
ctrl.StartAngle = initAngle;
initAngle += angleUnit;
}
_timer.Start();
}
/// <summary>
/// Stop the animation
/// </summary>
public void Stop()
{
_timer.Stop();
}
public List<ControlState> Controls
{
get { return _controls; }
}
/// <summary>
/// Continue
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void _timer_Tick(object sender, EventArgs e)
{
foreach (ControlState ctrl in _controls)
{
Rotate(ctrl);
}
}
/// <summary>
/// Used to update the mouse position.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void form_MouseMove(object sender, MouseEventArgs e)
{
_mouseX = e.X;
}
/// <summary>
/// calculate speed
/// </summary>
/// <param name="num"></param>
/// <returns></returns>
private float Speed(int num)
{
return -(_mouseX - _hx)* 1.0f / num;
}
/// <summary>
/// rotate the control
/// </summary>
/// <param name="ctrlState"></param>
private void Rotate(ControlState ctrlState)
{
if (_stopped == false)
{
//Calculate the moving distance
_p += Speed(NUM);
_range = ((_p + ANGLE_OFFSET) * Math.PI) / 180;
_range += ctrlState.StartAngle;
//Canculate factors
int re1 = (int)((Math.Sin(_range)) * _r);
int re2 = (int)((Math.Cos(_range)) * _a);
SetControl(ctrlState, re1, re2);
}
}
/// <summary>
/// Set some properties of the control
/// </summary>
/// <param name="ctrlState">control information</param>
/// <param name="re1">factor 1</param>
/// <param name="re2">factor 2</param>
private void SetControl(ControlState ctrlState,int re1, int re2)
{
//Change the location
ctrlState.Control.Location = new Point(
ctrlState.StartLocation.X + re1 + ctrlState.StartSize.Width / 2 + LOCATION_OFFSET,
ctrlState.StartLocation.Y);
// Calculate change rate
float rate = (re2 + 70) * 1.0f / 100;
//Change color gradually
int r = (int)(ctrlState.StartColor.R + (ctrlState.Control.BackColor.R - ctrlState.StartColor.R) * (1 - rate));
int g = (int)(ctrlState.StartColor.G + (ctrlState.Control.BackColor.G - ctrlState.StartColor.G) * (1 - rate));
int b = (int)(ctrlState.StartColor.B + (ctrlState.Control.BackColor.B - ctrlState.StartColor.B) * (1 - rate));
ctrlState.Control.ForeColor = Color.FromArgb(1,r,g,b);
//Scale the control
ctrlState.Control.Size = Size.Round(new SizeF(ctrlState.StartSize.Width * rate, ctrlState.StartSize.Height * rate));
ctrlState.Control.Font = new Font(ctrlState.Control.Font.FontFamily, ctrlState.Control.Height * FONT_BUTTON_WIDTH__RATE);
}
private int _hx = 0;
private int _r = 0;
private int _a = 30;
private int _mouseX = 0;
private double _range = 0;
private float _p;
private bool _stopped = false;
private List<ControlState> _controls = new List<ControlState>();
private Timer _timer = new Timer();
private const int NUM = 200;
private const int ANGLE_OFFSET = 144;
private const float FONT_BUTTON_WIDTH__RATE = 40.0f / 137;
private const int LOCATION_OFFSET = 50;
private const float FONT_CHANGE_MOUSE_ON = 1.2f;
}
/// <summary>
/// Save the initial information of the control
/// </summary>
internal class ControlState
{
public Control Control { set; get; }
public Point StartLocation { set; get; }
public Size StartSize { set; get; }
public float StartAngle { set; get; }
public Color StartColor { set; get; }
}
To be continued �/span>
Please mark the replies as answers if they help and unmark if they don't.