Загрузка данных


{$apptype windows}
{$reference 'System.Windows.Forms.dll'}
{$reference 'System.Drawing.dll'}

uses System, System.Drawing, System.Windows.Forms;

type
  Form1 = class(Form)
    button1: Button;
    button2: Button;
    pictureBox1: PictureBox;
    pictureBox2: PictureBox;
    
    constructor;
    begin
      self.Text := 'Рисунок на форме';
      self.Width := 670;
      self.Height := 450;
      self.StartPosition := FormStartPosition.CenterScreen;
      
      try
        self.BackgroundImage := Image.FromFile('лес (2).jpg');
        self.BackgroundImageLayout := ImageLayout.Stretch;
      except
      end;
      
      self.Load += Form1_Load;

      button1 := new Button();
      button1.Text := 'Медведь';
      button1.Location := new System.Drawing.Point(20, 20);
      button1.Size := new System.Drawing.Size(100, 30);
      button1.Click += button1_Click;
      self.Controls.Add(button1);

      button2 := new Button();
      button2.Text := 'Белка';
      button2.Location := new System.Drawing.Point(130, 20);
      button2.Size := new System.Drawing.Size(100, 30);
      button2.Click += button2_Click;
      self.Controls.Add(button2);

      pictureBox1 := new PictureBox();
      pictureBox1.Size := new System.Drawing.Size(200, 120);
      pictureBox1.SizeMode := PictureBoxSizeMode.StretchImage;
      pictureBox1.BackColor := Color.Transparent;
      pictureBox1.Visible := false;
      try
        pictureBox1.Image := Image.FromFile('медведь (2).png');
      except
      end;
      self.Controls.Add(pictureBox1);

      pictureBox2 := new PictureBox();
      pictureBox2.Size := new System.Drawing.Size(100, 100);
      pictureBox2.SizeMode := PictureBoxSizeMode.StretchImage;
      pictureBox2.BackColor := Color.Transparent;
      pictureBox2.Visible := false;
      try
        pictureBox2.Image := Image.FromFile('белка (2).png');
      except
      end;
      self.Controls.Add(pictureBox2);
    end;

    procedure Form1_Load(sender: Object; e: EventArgs);
    begin
      self.DoubleBuffered := true;
    end;

    procedure button1_Click(sender: Object; e: EventArgs);
    begin
      pictureBox1.Top := 220;
      var rnd: Random := new Random();
      pictureBox1.Left := rnd.Next(0, self.Width - pictureBox1.Width);
      pictureBox1.Visible := true;
    end;

    procedure button2_Click(sender: Object; e: EventArgs);
    begin
      var rnd: Random := new Random();
      pictureBox2.Top := rnd.Next(30, 120);
      pictureBox2.Left := rnd.Next(50, self.Width - pictureBox2.Width);
      pictureBox2.Visible := true;
    end;
  end;

begin
  Application.Run(new Form1());
end.