vendredi 18 novembre 2016

Create Button in random places of form C#.NET

i want to create 20 buttons in random places of a form in C#.net. my code is written below , but it doesn't work correctly ! some buttons drop into each other and some of them goes out of form . tnx for your help.

int x,y;
            for (int i = 1; i <= 20; i++)
            {
                Random rnd = new Random(Math.Abs(Guid.NewGuid().GetHashCode()));
                x = rnd.Next(this.Width-50);
                y = rnd.Next(this.Height-50);
                Button btn = new Button();
                btn.Location = new Point(x, y);
                this.Controls.Add(btn);
            }




Aucun commentaire:

Enregistrer un commentaire