Solutions

Exercice 1.

private void btnRaz_Click(object sender, System.EventArgs e)
{
      lblBonjour.Text="";
      txtNom.Text="";
}

retour

Exercice 2 : plus grand, plus petit, première partie

public Form1()
{
          InitializeComponent();
          Random r = new Random();
          nbCherche = r.Next(1000);
          numEssai=1;
          MessageBox.Show(nbCherche.ToString());
          lblNumEssai.Text= "Essai numéro "+numEssai.ToString();
}

retour

Exercice 2 : plus grand, plus petit, deuxième partie

private void btnTest_Click(object sender, System.EventArgs e)
{
         int nb = Convert.ToInt32(txtEssai.Text);
         if(nb<nbCherche)
         MessageBox.Show("trop petit");
         if(nb>nbCherche)
         MessageBox.Show("trop grand");
         if(nb==nbCherche)
         MessageBox.Show("C'est gagné");
         numEssai++;
         lblNumEssai.Text= "Essai numéro "+numEssai.ToString();
         if(numEssai>MAX)
         btnTester.Enabled=false;
}

private void btnEffacer_Click(object sender, System.EventArgs e)
{
          txtEssai.Text="";
          txtEssai.Focus(); // met le curseur dans la zone de texte, le contrôle prend le focus
}

retour

Exercice 2 Evolution

private void btnebut_Click(object sender, System.EventArgs e)
{
      txtEssai.Text="";
      txtEssai.Focus();
      Random r = new Random();
      nbCherche = r.Next(1000);
      numEssai=1;
      lblNumEssai.Text= "Essai numéro "+numEssai.ToString();
}

retour

Exercice 2 Chrono Déclarations

public class Form1 : System.Windows.Forms.Form
{
        private System.Windows.Forms.TextBox txtEssai;
        private System.Windows.Forms.Label lblNumEssai;
        private System.Windows.Forms.Button btnTester;
        private System.Windows.Forms.Button btnEffacer;
        private int nbCherche;
        private int numEssai;
        private const int MAX = 8;
        private const int MAXTEMPS = 60;
        private int tempsRestant;
         private System.Windows.Forms.Timer timer1;
...

Retour

Exercice 2 Chrono

private void btnebut_Click(object sender, System.EventArgs e)
{
         tempsRestant=MAXTEMPS;
         txtEssai.Text="";
         txtEssai.Focus();
         timer1.Enabled=true;
         Random r = new Random();
         nbCherche = r.Next(1000);
         MessageBox.Show(nbCherche.ToString());
         numEssai=1;
         lblNumEssai.Text= "Essai numéro "+numEssai.ToString();
}

private void timer1_Tick(object sender, System.EventArgs e)
{
     tempsRestant--;
     lblTemps.Text=tempsRestant.ToString();
     if(tempsRestants<=0)
           btnTester.Enabled=false;
}

retour