This is the important function of the User Control. I do the animation for the selected current Image. This function will be called in the Timer Tick event . After the Animation is finished I stop the timer and activate the main timer to load the next image. From the main Timer I create a random number from 1 to 11 and activate the sub timer. the sub timer is used to display the animation. I have commented in each case about the use.
#region Draw Animation on seleced Image
// Small to Big Size Image
private void SmalltoBigImage_Animation()
{
int leftConstant_adjust = 40;
int topconstant_adjust = 30;
if ((picImageSlide.Width < (MINMAX * pnlImg.Width)) &&
(picImageSlide.Height < (MINMAX * pnlImg.Height)))
{
picImageSlide.Width = Convert.ToInt32(picImageSlide.Width * ZOOMFACTOR);
picImageSlide.Height = Convert.ToInt32(picImageSlide.Height * ZOOMFACTOR);
picImageSlide.Left = Convert.ToInt32(picImageSlide.Left - leftConstant_adjust);
if (picImageSlide.Top <= 0)
{
picImageSlide.Left = 0;
picImageSlide.Top = 0;
}
picImageSlide.Top = Convert.ToInt32(picImageSlide.Top - topconstant_adjust);
picImageSlide.SizeMode = PictureBoxSizeMode.StretchImage;
}
else
//In else part i check for the animation completed if its completed stop the timer 2 and start the timer 1 to load the next image .
{
picImageSlide.Width = pnlImg.Width;
picImageSlide.Height = pnlImg.Height;
Start_Stop_Timer_1(true); // Start the Timer 1 to load the next Image
Start_Stop_Timer_2(false);// Stop the Timer 2 to stop the animation till the next image loaded.
}
}
//Left to Right Animation
private void LefttoRight_Animation()
{
picImageSlide.Invalidate();
if (picImageSlide.Location.X >= 10)
{
picImageSlide.Left = 0;
Start_Stop_Timer_1(true); // Start the Timer 1 to load the next Image
Start_Stop_Timer_2(false);// Stop the Timer 2 to stop the animation till the next image loaded.
}
else
{
picImageSlide.Left = xval;
xval = xval + 100;
}
picImageSlide.Width = pnlImg.Width;
picImageSlide.Height = pnlImg.Height;
}
//Left to Right Animation
private void Transparent_Bar_Animation()
{
// picImageSlide.Invalidate();
if (opacity >= 90)
{
Start_Stop_Timer_1(true); // Start the Timer 1 to load the next Image
Start_Stop_Timer_2(false);// Stop the Timer 2 to stop the animation till the next image loaded.
opacity = 100;
}
// picImageSlide.Refresh();
Graphics g = Graphics.FromImage(picImageSlide.Image);
g.FillRectangle(new SolidBrush(Color.FromArgb(58, Color.White)), 0, 0, picImageSlide.Image.Width, picImageSlide.Image.Height);
opacity = opacity + 10;
picImageSlide.Image = PictuerBoxFadeIn(picImageSlide.Image, opacity); //calling ChangeOpacity Function
}
// Right to Left Animation
private void RighttoLeft_Animation()
{
picImageSlide.Invalidate();
if (xval_Right <= 100)
{
picImageSlide.Left = 0;
xval_Right = 0;
Start_Stop_Timer_1(true); // Start the Timer 1 to load the next Image
Start_Stop_Timer_2(false);// Stop the Timer 2 to stop the animation till the next image loaded.
}
else
{
picImageSlide.Left = xval_Right;
xval_Right = xval_Right - 100;
}
picImageSlide.Width = pnlImg.Width;
picImageSlide.Height = pnlImg.Height;
}
// Top to Bottom Slide Animation
private void ToptoBottom_Animation()
{
picImageSlide.Invalidate();
if (yval + 60 >= 30)
{
picImageSlide.Top = 0;
Start_Stop_Timer_1(true); // Start the Timer 1 to load the next Image
Start_Stop_Timer_2(false);// Stop the Timer 2 to stop the animation till the next image loaded.
}
else
{
picImageSlide.Top = yval;
yval = yval + 100;
}
picImageSlide.Width = pnlImg.Width;
picImageSlide.Height = pnlImg.Height;
}
// Bottom to Top Slide Animation
private void BottomTop_Animation()
{
picImageSlide.Invalidate();
if (yval_Right <= 0)
{
picImageSlide.Left = 0;
xval_Right = 0;
Start_Stop_Timer_1(true); // Start the Timer 1 to load the next Image
Start_Stop_Timer_2(false);// Stop the Timer 2 to stop the animation till the next image loaded.
}
else
{
picImageSlide.Top = yval_Right;
yval_Right = yval_Right - 100;
}
picImageSlide.Width = pnlImg.Width;
picImageSlide.Height = pnlImg.Height;
}
// vertical transparent Bar Animation
private void Vertical_Bar_Animation()
{
if (opacity_new <= 0)
{
Start_Stop_Timer_1(true); // Start the Timer 1 to load the next Image
Start_Stop_Timer_2(false);// Stop the Timer 2 to stop the animation till the next image loaded.
opacity_new = 100;
}
// picImageSlide.Refresh();
Graphics g2 = Graphics.FromImage(picImageSlide.Image);
recBlockYval = 0;
barheight = barheight + 100;
g2.DrawRectangle(Pens.Black, recBlockXval, recBlockYval, barwidth, barheight);
g2.FillRectangle(new SolidBrush(Color.FromArgb(opacity_new, Color.White)), recBlockXval, recBlockYval, barwidth - 1, barheight - 1);
opacity_new = opacity_new - 10;
recBlockXval = recBlockXval + barwidth + 4;
picImageSlide.Refresh();
}
// Random bar and Circle transparent Animation
private void Random_Bar_Animation()
{
if (opacity_new <= 0)
{
Start_Stop_Timer_1(true); // Start the Timer 1 to load the next Image
Start_Stop_Timer_2(false);// Stop the Timer 2 to stop the animation till the next image loaded.
opacity_new = 100;
}
// picImageSlide.Refresh();
Graphics g3 = Graphics.FromImage(picImageSlide.Image);
recBlockXval = 0;
barwidth = barwidth + 100;
// g3.DrawRectangle(Pens.Black, rnd.Next(0, 200), rnd.Next(0, 200), rnd.Next(100, 600), rnd.Next(60, 400));
g3.FillRectangle(new SolidBrush(Color.FromArgb(opacity_new, Color.White)), rnd.Next(10, 600), rnd.Next(10, 600), rnd.Next(100, 600), rnd.Next(60, 400));
opacity_new = opacity_new - 5;
recBlockYval = recBlockYval + barheight + 4;
//recBlockYval = recBlockYval + 100;
//barheight = barheight + 100;
picImageSlide.Refresh();
}
//Horizontal transparent Bar Animation
private void Horizontal_Bar_Animation()
{
if (opacity_new <= 0)
{
Start_Stop_Timer_1(true); // Start the Timer 1 to load the next Image
Start_Stop_Timer_2(false);// Stop the Timer 2 to stop the animation till the next image loaded.
opacity_new = 100;
}
recBlockXval = 0;
barwidth = barwidth + 100;
Graphics g4 = Graphics.FromImage(picImageSlide.Image);
g4.DrawRectangle(Pens.Black, recBlockXval, recBlockYval, barwidth, barheight);
g4.FillRectangle(new SolidBrush(Color.FromArgb(opacity_new, Color.White)), recBlockXval, recBlockYval, barwidth - 1, barheight - 1);
opacity_new = opacity_new - 10;
recBlockYval = recBlockYval + barheight + 4;
picImageSlide.Refresh();
}
// transparent text Animation
private void Transparent_Text_Animation()
{
if (opacity_new <= 0)
{
Start_Stop_Timer_1(true); // Start the Timer 1 to load the next Image
Start_Stop_Timer_2(false);// Stop the Timer 2 to stop the animation till the next image loaded.
opacity_new = 100;
}
// picImageSlide.Refresh();
Graphics g5 = Graphics.FromImage(picImageSlide.Image);
g5.DrawString("Shanu Slide Show", new Font("Arial", 86),
new SolidBrush(Color.FromArgb(opacity_new, Color.FromArgb(this.rnd.Next(256), this.rnd.Next(256), this.rnd.Next(256)))),
rnd.Next(600), rnd.Next(400));
opacity_new = opacity_new - 5;
picImageSlide.Refresh();
}
// Random Circle Animation
private void Random_Circle_Animation()
{
if (opacity_new <= 0)
{
Start_Stop_Timer_1(true); // Start the Timer 1 to load the next Image
Start_Stop_Timer_2(false);// Stop the Timer 2 to stop the animation till the next image loaded.
opacity_new = 100;
}
// picImageSlide.Refresh();
Graphics g6 = Graphics.FromImage(picImageSlide.Image);
recBlockXval = 0;
barwidth = barwidth + 100;
// g3.DrawRectangle(Pens.Black, rnd.Next(0, 200), rnd.Next(0, 200), rnd.Next(100, 600), rnd.Next(60, 400));
g6.FillRectangle(new SolidBrush(Color.FromArgb(opacity_new, Color.White)), rnd.Next(10, 600), rnd.Next(10, 600), rnd.Next(400, 800), rnd.Next(60, 400));
g6.FillPie(new SolidBrush(Color.FromArgb(opacity_new, Color.FromArgb(this.rnd.Next(256), this.rnd.Next(256), this.rnd.Next(256)))), rnd.Next(600), rnd.Next(400), rnd.Next(400, 800), rnd.Next(400), 0, 360)
opacity_new = opacity_new - 5;
recBlockYval = recBlockYval + barheight + 4;
//recBlockYval = recBlockYval + 100;
//barheight = barheight + 100;
picImageSlide.Refresh();
}
public void drawAnimation()
{
try
{
switch (SlideType)
{
case 0:// Small to big
SmalltoBigImage_Animation();
break;
case 1:// left to right
LefttoRight_Animation();
break;
case 2:// Rectangle Transparent
Transparent_Bar_Animation();
break;
case 3:// Right to Left
RighttoLeft_Animation();
break;
case 4:// Top to Bottom
ToptoBottom_Animation();
break;
case 5:// Bottom to Top
BottomTop_Animation();
break;
case 6:// Rectangle Vertical Block Transparent
Vertical_Bar_Animation();
break;
case 7:// Random Block Transparent
Random_Bar_Animation();
break;
case 8:// Rectangle Horizontal Block Transparent
Horizontal_Bar_Animation();
break;
case 9:// Text Transparent
Transparent_Text_Animation();
break;
case 10:// Random Circle and Bar Transparent
Random_Circle_Animation();
break;
default: // In Default there is no animation but load next image in time intervals.
picImageSlide.Width = pnlImg.Width;
picImageSlide.Height = pnlImg.Height;
timer1.Enabled = true;
timer1.Start();
break;
}
}
catch (Exception ex)
{
}
}
//for the Image Transparent
public static Bitmap PictuerBoxFadeIn(Image img, int opacity)
{
Bitmap bmp = new Bitmap(img.Width, img.Height);
Graphics g = Graphics.FromImage(bmp);
ColorMatrix colmat = new ColorMatrix();
colmat.Matrix33 = opacity;
ImageAttributes imgAttr = new ImageAttributes();
imgAttr.SetColorMatrix(colmat, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imgAttr);
g.Dispose();
// return the new fade in Image
return bmp;
}
#endregion