Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class SplashScreenExtenstion
- {
- public static void ShowSplashScreen(this Control control, SplashScreen splashScreen)
- {
- PictureBox pb = new PictureBox() { Size = control.Size };
- control.Controls.Add(pb);
- pb.BringToFront();
- int time = 0;
- pb.Paint += (o, e) => splashScreen.Draw(e.Graphics, control.ClientSize, time);
- System.Timers.Timer t = new System.Timers.Timer(1000);
- t.Elapsed += (o, e) =>
- {
- if (++time >= splashScreen.TotalTime)
- {
- t.Dispose();
- control.Invoke(new Action(() => control.Controls.Remove(pb)));
- }
- pb.Invoke(new Action(() => pb.Refresh()));
- };
- t.Start();
- }
- }
- public class SplashScreen
- {
- private Color background;
- private Image image;
- private int t1, t2;
- public int TotalTime
- {
- get { return t1 + t2; }
- }
- public SplashScreen(Color background, int t1, Image image, int t2)
- {
- this.background = background;
- this.image = image;
- this.t1 = t1;
- this.t2 = t2;
- }
- public void Draw(Graphics g, Size size, int time)
- {
- if (time < t1)
- g.FillRectangle(new SolidBrush(background), 0, 0, size.Width, size.Height);
- else if (time >= t1 && time <= TotalTime)
- g.DrawImage(image, 0, 0, size.Width, size.Height);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement