Fenêtre s'affichant durant un intervalle de temps donné

Contenu du snippet

Il s'agit d'une fenêtre d'attente s'affichant durant le temps nécéssaire au chargement d'une application, d'un logiciel ou autre. Word, Powerpoint outres softs fonctionnent selon ce principe.

Bon dev.

Gz.

Source / Exemple :


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace MyProject
{
	/// <summary>
	/// Fenêtre s'affichant durant un intervalle de temps.
	/// </summary>
	/// <remarks>L'intervalle par défaut est fixée à 3 secondes.</remarks>
	public class frmSplash : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Timer timer1;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private const int DEFAULT_TIMER_INTERVAL = 3;

		/// <summary>
		/// Permet d'obtenir une instance de la classe frmSplash.
		/// </summary>
		/// <remarks>La durée d'affichage par défaut de cette WinForm est fixée à 3 secondes.<seealso cref="frmSplash(int intInterval)"/></remarks>
		public frmSplash()
		{
			InitializeComponent();
			InitializeTimer(DEFAULT_TIMER_INTERVAL);
			StartTimer();
		}

		/// <summary>
		/// Permet d'obtenir une instance de la classe frmSplash.
		/// </summary>
		/// <param name="intInterval">Représente l'intervalle durant laquelle la fenêtre devra s'afficher.</param>
		/// <remarks>Cette valeur devra être exprimée en secondes.</remarks>
		public frmSplash(int intInterval)
		{
			InitializeComponent();
			InitializeTimer(intInterval);
			StartTimer();
		}

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new frmSplash(5));
		}

		/// <summary>
		/// Nettoyage des ressources utilisées.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
		/// le contenu de cette méthode avec l'éditeur de code.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			this.label1 = new System.Windows.Forms.Label();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label6 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("Comic Sans MS", 20.25F, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic), System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(136, 80);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(136, 32);
			this.label1.TabIndex = 0;
			this.label1.Text = "Splash";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// timer1
			// 
			this.timer1.Interval = 1000;
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.Location = new System.Drawing.Point(104, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(96, 23);
			this.label2.TabIndex = 1;
			this.label2.Text = "Godzidane";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label3
			// 
			this.label3.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label3.Location = new System.Drawing.Point(16, 160);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(96, 16);
			this.label3.TabIndex = 2;
			this.label3.Text = "Copyrigth 2003";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label4
			// 
			this.label4.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label4.Location = new System.Drawing.Point(240, 144);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(112, 16);
			this.label4.TabIndex = 3;
			this.label4.Text = "Windows 2000, XP";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label5
			// 
			this.label5.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label5.Location = new System.Drawing.Point(272, 160);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(80, 16);
			this.label5.TabIndex = 4;
			this.label5.Text = "Version 1.0.0";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label6
			// 
			this.label6.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label6.Location = new System.Drawing.Point(168, 8);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(184, 16);
			this.label6.TabIndex = 5;
			this.label6.Text = "Ce produit est sous licence GNU";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// frmSplash
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(366, 190);
			this.ControlBox = false;
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.label6,
																		  this.label5,
																		  this.label4,
																		  this.label3,
																		  this.label2,
																		  this.label1});
			this.Enabled = false;
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Name = "frmSplash";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.TopMost = true;
			this.ResumeLayout(false);

		}
		#endregion

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			StopTimer();
			this.Close();
		}

		/// <summary>
		/// Permet d'initialiser le contrôle timer.
		/// </summary>
		/// <param name="intNbSecond">Durée durant laquelle le contrôle timer devra être activé.</param>
		private void InitializeTimer(int intNbSecond)
		{
			timer1.Interval = 1000 * intNbSecond;
		}

		/// <summary>
		/// Permet d'activer et de démarrer le contrôle timer.
		/// </summary>
		private void StartTimer()
		{
			timer1.Enabled = true;
			timer1.Start();
		}

		/// <summary>
		/// Permet d'arrêter et de désactiver le contrôle timer.
		/// </summary>
		private void StopTimer()
		{
			timer1.Stop();
			timer1.Enabled = false;
		}
	}
}

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.