Classtan Nesne Üretme (Forma Rastgele Resim Nesnesi Ekleme)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Rebar;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            int i = 0;
            while (i < 10)
            {
                new UzayGemisi(this);
                i++;
            }
        }
    }

    public class UzayGemisi
    {
        int konumX = 0;
        int konumY = 0;

        public UzayGemisi(Form FormGelen)
        {

            System.Threading.Thread.Sleep(1000);

            PictureBox pb1 = new PictureBox();
            pb1.Image = Image.FromFile("D:UsersÖğretmenDownloadsrocket-158_128.gif");

            Random Rastgele = new Random();
            //MessageBox.Show(FormGelen.Width.ToString());
            int KoordinatX = Rastgele.Next(FormGelen.Width);
            int KoordinatY = Rastgele.Next(FormGelen.Height);


            pb1.Location = new Point(KoordinatX, KoordinatY);
            pb1.Size = new Size(100, 110);

            FormGelen.Controls.Add(pb1);

        }
    }

}

 

Yorumunuzu Ekleyin


Yükleniyor...
Yükleniyor...