קוד:
#region Graphic Laibrary
public class ImagesAnimation : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public ImagesAnimation(int animationDelay)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
animationTimer.Tick += new EventHandler(Animation);
animationTimer.Interval = animationDelay;
}
public ImagesAnimation()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
animationTimer.Tick += new EventHandler(Animation);
animationTimer.Interval = 300;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Images Animation
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "ImagesAnimation";
this.ShowInTaskbar = false;
this.TransparencyKey = System.Drawing.SystemColors.Control;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
}
#endregion
Hashtable imagesHashtable = new Hashtable();
Point notInScreenPoint = new Point(3000,3000);
Point animationPoint = new Point(0,0);
int AddX = 5;
int AddY = 0;
Timer animationTimer = new Timer();
int animationIndex = 0;
int loops;
int currentLoop = 0;
int animationLastIndex;
string[] animationKeys;
Graphics myGrfx;
public int AnimationDelay
{
get
{
return animationTimer.Interval;
}
set
{
animationTimer.Interval = value;
}
}
private void Animation(object obj, EventArgs e)
{
animationTimer.Stop();
animationPoint.X += AddX;
animationPoint.Y += AddY;
ImageForm thisImageForm = imagesHashtable[animationKeys[animationIndex]] as ImageForm;
thisImageForm.Location = animationPoint;
thisImageForm.Visible = true;
if ((currentLoop != 0)||(animationIndex != 0))
{
ImageForm lastImageForm = imagesHashtable[animationKeys[animationLastIndex]] as ImageForm;
lastImageForm.Visible = false;
}
animationLastIndex = animationIndex;
if (animationIndex == animationKeys.Length - 1)
{
if (currentLoop == loops)
return;
animationIndex = 0;
currentLoop ++;
}
else
animationIndex ++;
animationTimer.Start();
}
public void ClearBG(Color bgColor)
{
myGrfx = CreateGraphics();
myGrfx.Clear(bgColor);
}
public void AddBG(Image backgroundImage,int width,int height)
{
myGrfx.DrawImage(backgroundImage,0,0,width,height) ;
}
public bool LoadImages(string[] imagesPath, string[] imagesKeys)
{
if (imagesPath.Length != imagesKeys.Length)
return false;
for (int i = 0;i < imagesPath.Length;i ++)
{
ImageForm imageForm = new ImageForm(Image.FromFile(imagesPath[i]));
imagesHashtable.Add(imagesKeys[i],imageForm);
}
return true;
}
public void ClearImages(string[] imagesToClear)
{
for (int i = 0; i < imagesToClear.Length; i++)
{
ImageForm imageForm = imagesHashtable[imagesToClear[i]] as ImageForm;
imageForm.Visible = false;
}
}
public void ShowForms(string[] formsKeys)
{
for (int i = 0;i < formsKeys.Length;i ++)
{
ImageForm imageForm = imagesHashtable[formsKeys[i]] as ImageForm;
imageForm.Location = animationPoint;
imageForm.Visible = false;
imageForm.Show();
}
}
public void Animate(string[] formsKeys,int addX,int addY,Point animationStartPosition,int animationLoops)
{
//Initialize Vars
loops = animationLoops;
AddX = addX;
AddY = addY;
animationPoint.X = animationStartPosition.X;
animationPoint.Y = animationStartPosition.Y;
ClearImages(formsKeys);
animationKeys = formsKeys;
animationPoint.X -= AddX;
animationPoint.Y -= AddY;
// Start Animation
animationTimer.Start();
}
}
public class ImageForm : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
Image imageToDrawGlobal;
public ImageForm(Image imageToDraw)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.Size = imageToDraw.Size;
imageToDrawGlobal = imageToDraw;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// ImageForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "ImageForm";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.TransparencyKey = System.Drawing.SystemColors.Control;
this.Closed += new System.EventHandler(this.ImageForm_Closed);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.ImageF orm_Paint);
}
#endregion
private void ImageForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics myGrfx = CreateGraphics();
myGrfx.DrawImage(imageToDrawGlobal,0,0);
}
private void ImageForm_Closed(object sender, System.EventArgs e)
{
Application.Exit();
}
}
public class KeysForm : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public KeysForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// KeysForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "KeysForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "KeysForm";
this.TopMost = true;
this.TransparencyKey = System.Drawing.SystemColors.Control;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Closing += new System.ComponentModel.CancelEventHandler(this.Keys Form_Closing);
this.ShowInTaskbar = false;
this.FormBorderStyle = FormBorderStyle.None;
}
#endregion
private void KeysForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Application.Exit();
}
}
#endregion