View difference between Paste ID: a5DA3f6Q and dTPFJVuY
SHOW: | | - or go back to the newest paste.
1-
	
1+
2
    using System.Collections.Generic;
3
    using System.ComponentModel;
4
    using System.Data;
5
    using System.Drawing;
6
    using System.Linq;
7
    using System.Text;
8
    using System.Threading.Tasks;
9
    using System.Windows.Forms;
10
     
11
    namespace Zufallszahlen
12
    {
13
        public partial class Form1 : Form
14
        {
15
            //Lösungsvorschlag:
16
           
17
            //Das von mir festgelegte Zahleneingabelimit für den Benutzer ist "9.999" (textBox.MaxLength = 4).
18
     
19
            //Alle (natürlichen) Zahlen von null bis 9.999 werden in einer (string-)Liste gespeichert.
20
     
21
            //Um zu überprüben, ob der Benutzer eine natürliche Zahl eingeben hat,
22
            //wird die Liste.Contains(var)-Methode angewandt.
23
     
24
            List<string> natürlicheZahlenBisZehntausend = new List<string>();
25
            Random x = new Random();
26
     
27
            public Form1()
28
            {
29
                InitializeComponent();
30
     
31
                for (int i = 0; i < 10000; i++)
32
                    natürlicheZahlenBisZehntausend.Add(i.ToString());
33
34
     		btn_Start.Text = "Zufallszahlen zwischen <min> und <max> ziehen"
35
                tb_Minimum.MaxLength = 4;
36
                tb_Maximum.MaxLength = 4;
37
            }
38
     
39
            private void btn_Start_Click(object sender, EventArgs e)
40-
                tb_Anzahl.MaxLength = 4;
40+
41
                if (!natürlicheZahlenBisZehntausend.Contains(tb_Minimum.Text) | !natürlicheZahlenBisZehntausend.Contains(tb_Maximum.Text))
42
                    MessageBox.Show("Bitte nur natürliche Zahlen eingeben.");
43
                else if (Convert.ToInt32(tb_Minimum.Text) > Convert.ToInt32(tb_Maximum.Text))
44
                    MessageBox.Show("Das Minimum muss kleiner als das Maximum sein.");
45
                else
46
                {
47
                    rtb_Ausgabe.Clear();
48
     
49
                    for (int i = 0; i < Convert.ToInt32(tb_Anzahl.Text); i++)
50
                        rtb_Ausgabe.Text += x.Next(Convert.ToInt32(tb_Minimum.Text), Convert.ToInt32(tb_Maximum.Text) + 1) + " ";
51
                }
52
            }
53
     
54
            private void tb_Minimum_TextChanged(object sender, EventArgs e)
55
            {
56
                btn_Start.Text = "Zufallszahlen zwischen " + tb_Minimum.Text + " und " + tb_Maximum.Text + " ziehen";
57
            }
58-
                    {
58+
59
            private void tb_Maximum_TextChanged(object sender, EventArgs e)
60-
                    }
60+
61
                btn_Start.Text = "Zufallszahlen zwischen " + tb_Minimum.Text + " und " + tb_Maximum.Text + " ziehen";
62
            }
63
        }
64
    }