Advertisement
Guest User

Untitled

a guest
Aug 31st, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. public static class SplashScreenExtenstion
  2. {
  3.     public static void ShowSplashScreen(this Control control, SplashScreen splashScreen)
  4.     {
  5.         PictureBox pb = new PictureBox() { Size = control.Size };
  6.         control.Controls.Add(pb);
  7.         pb.BringToFront();
  8.         int time = 0;
  9.         pb.Paint += (o, e) => splashScreen.Draw(e.Graphics, control.ClientSize, time);
  10.         System.Timers.Timer t = new System.Timers.Timer(1000);
  11.         t.Elapsed += (o, e) =>
  12.         {
  13.             if (++time >= splashScreen.TotalTime)
  14.             {
  15.                 t.Dispose();
  16.                 control.Invoke(new Action(() => control.Controls.Remove(pb)));
  17.             }
  18.             pb.Invoke(new Action(() => pb.Refresh()));
  19.         };
  20.         t.Start();
  21.     }
  22. }
  23.  
  24. public class SplashScreen
  25. {
  26.     private Color background;
  27.     private Image image;
  28.     private int t1, t2;
  29.  
  30.     public int TotalTime
  31.     {
  32.         get { return t1 + t2; }
  33.     }
  34.  
  35.     public SplashScreen(Color background, int t1, Image image, int t2)
  36.     {
  37.         this.background = background;
  38.         this.image = image;
  39.         this.t1 = t1;
  40.         this.t2 = t2;
  41.     }
  42.  
  43.     public void Draw(Graphics g, Size size, int time)
  44.     {
  45.         if (time < t1)
  46.             g.FillRectangle(new SolidBrush(background), 0, 0, size.Width, size.Height);
  47.         else if (time >= t1 && time <= TotalTime)
  48.             g.DrawImage(image, 0, 0, size.Width, size.Height);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement