Meilleur auteur de réponses
ProgresseBar avec un thread inclus dans le form

Question
-
Bonjour
Mon probleme est le suivant
j'utilise ceci
public SForm() { InitializeComponent(); } private void SForm_Load(object sender, EventArgs e) { this.Text = Application.ProductName + " - Version: " + Application.ProductVersion; this.label1.Text = AssemblyProduct; this.label2.Text = String.Format("Version {0}", AssemblyVersion); this.label3.Text = AssemblyCopyright; this.label4.Text = AssemblyCompany; this.label5.Text = AssemblyDescription; } private void SForm_Shown(object sender, EventArgs e) { Application.DoEvents(); Thread.Sleep(15000); mForm MF = new mForm(); MF.Show(); this.Hide(); }
j'aimerais savoir comment inserrer le progressbar pour qu'il fonctionne avec le thread.Sleep() du form
Merci...
Daniel
Réponses
-
Bonjour,
Il faudrait dans ce cas faire le code suivant :
mForm MF = new mForm(); MF.Show(); for (int i = 0; i < 15; i++) { this.progressBar.Value++; Application.DoEvents(); Thread.Sleep(1000); } this.Hide();
Il faudra au préalable spécifier dans les propriétés du ProgressBar : Minimum = 15.
Cordialement
Gilles TOURREAU - MVP C#
Architecte logiciel/Consultant/Formateur Freelance - P.O.S Informatique
Blog : http://gilles.tourreau.fr - Suivez-moi sur Twitter
- MCPD : Enterprise Developper / Windows Developper 3.5 / ASP .NET 3.5/4.0
- MCSA : SQL Server 2012
- MCITP : SQL Server 2008 Developper
- MCTS : ADO .NET 3.5 / SQL Server 2008 Developper / Windows Forms 3.5 / ASP .NET 3.5/4.0 / TFS 2010 / Windows Azure- Marqué comme réponse DanielMorais samedi 12 octobre 2013 13:09
Toutes les réponses
-
Bonjour,
Il faudrait dans ce cas faire le code suivant :
mForm MF = new mForm(); MF.Show(); for (int i = 0; i < 15; i++) { this.progressBar.Value++; Application.DoEvents(); Thread.Sleep(1000); } this.Hide();
Il faudra au préalable spécifier dans les propriétés du ProgressBar : Minimum = 15.
Cordialement
Gilles TOURREAU - MVP C#
Architecte logiciel/Consultant/Formateur Freelance - P.O.S Informatique
Blog : http://gilles.tourreau.fr - Suivez-moi sur Twitter
- MCPD : Enterprise Developper / Windows Developper 3.5 / ASP .NET 3.5/4.0
- MCSA : SQL Server 2012
- MCITP : SQL Server 2008 Developper
- MCTS : ADO .NET 3.5 / SQL Server 2008 Developper / Windows Forms 3.5 / ASP .NET 3.5/4.0 / TFS 2010 / Windows Azure- Marqué comme réponse DanielMorais samedi 12 octobre 2013 13:09
-
-
Bonjour Gilles
J'ai essayer de l'adapter mais ca pas fonctionné
Alors je suis tourner vers ce bout de code que j'ai retrouvé en fouillant bien et voici ce que ca donne
Form1 est le mainform Form1 using System; using System.IO; using System.Text; using System.Drawing; using System.Threading; using System.Windows.Forms; using DMWFA5.Properties; namespace %Name of solution% { public partial class form1: Form { public form1() { Thread t = new Thread(new ThreadStart(%Name of solution%)); t.Start(); Thread.Sleep(1000); InitializeComponent(); t.Abort(); } public void %Name of solution%() { Application.Run(new Form2()); } } } //***********************************************************************************************************// Form2 est le SplashForm une images de fond plus un proplus un Timer Form2 //***********************************************************************************************************// using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Reflection; using System.Linq; using System.Text; using System.Windows.Forms; namespace %Name of solution% { public partial class sForm : Form { public sForm() { InitializeComponent(); } private void timer1_Tick(object sender, EventArgs e) { progressBar1.Increment(1); if (progressBar1.Value == 15) timer1.Stop(); } } }
Jusqu'ici pas de probleme
Merci
Daniel
- Modifié DanielMorais samedi 12 octobre 2013 21:16