Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void btnnumerovoti_Click(object sender, EventArgs e)
- {
- LP1.Controls.Clear();
- // Mettere il controllo che sia un numero e non una stringa
- int n = Int32.Parse(txtnumerovoti.Text);
- lblnumerovoti.Text = "voti " + "(" + n + ")";
- for (int i = 0; i < n; i++)
- {
- TextBox textbox = new TextBox();
- Button button = new Button();
- Label label = new Label();
- button.Click += (s, ev) => {
- if (Int32.Parse(textbox.Text)<6)
- {
- label.ForeColor = System.Drawing.Color.Red;
- }
- else
- {
- label.ForeColor = System.Drawing.Color.Green;
- }
- label.Text = textbox.Text;
- };
- textbox.Name = $"Texta{i}";
- textbox.Text = "";
- button.Name = $"Bottone{i}";
- button.Text = $"Inserisci";
- label.Name = $"Testoa{i}";
- label.Text = "";
- LP1.Controls.Add(textbox);
- LP1.Controls.Add(button);
- LP2.Controls.Add(label);
- int som = 0;
- int med = 0;
- som = (int.Parse(label.Text.ToString())) + som;
- med = som / n;
- }
- lblmedia.Text = med;
- txtnumerovoti.Text = "";
- txtnumerovoti.Enabled = false;
- btnnumerovoti.Enabled = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement