Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. private void btnnumerovoti_Click(object sender, EventArgs e)
  2.         {
  3.  
  4.             LP1.Controls.Clear();
  5.  
  6.             // Mettere il controllo che sia un numero e non una stringa
  7.             int n = Int32.Parse(txtnumerovoti.Text);
  8.  
  9.             lblnumerovoti.Text = "voti " + "(" + n + ")";
  10.  
  11.             for (int i = 0; i < n; i++)
  12.             {
  13.                 TextBox textbox = new TextBox();
  14.                 Button button = new Button();
  15.                 Label label = new Label();
  16.  
  17.                 button.Click += (s, ev) => {
  18.                     if (Int32.Parse(textbox.Text)<6)
  19.                     {
  20.                         label.ForeColor = System.Drawing.Color.Red;
  21.                     }
  22.                     else
  23.                     {
  24.                         label.ForeColor = System.Drawing.Color.Green;
  25.                     }
  26.  
  27.                     label.Text = textbox.Text;
  28.                 };
  29.  
  30.                 textbox.Name = $"Texta{i}";
  31.                 textbox.Text = "";
  32.                 button.Name = $"Bottone{i}";
  33.                 button.Text = $"Inserisci";
  34.                 label.Name = $"Testoa{i}";
  35.                 label.Text = "";
  36.  
  37.  
  38.                 LP1.Controls.Add(textbox);
  39.                 LP1.Controls.Add(button);
  40.                 LP2.Controls.Add(label);
  41.  
  42.                 int som = 0;
  43.                 int med = 0;
  44.  
  45.                 som = (int.Parse(label.Text.ToString())) + som;
  46.  
  47.                 med = som / n;
  48.             }
  49.  
  50.             lblmedia.Text = med;
  51.  
  52.             txtnumerovoti.Text = "";
  53.             txtnumerovoti.Enabled = false;
  54.             btnnumerovoti.Enabled = false;
  55.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement