Не появляются на форме picturebox-ы. Если после каждого добавления пикчебокса вызывать messagebox, или код функции random_points() вставить в обработчик события timer_Tick(object sender, EventArgs e), то всё прорисовывается. Что нужно поправить?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Генерация_точек
{
public partial class MajorForm : Form
{
int n = 0;
PictureBox[] points = new PictureBox[65];
private Point generateXY()
{
int X, Y;
Random r = new Random();
X = r.Next(0, this.Width);
Y = r.Next(0, this.Height);
return new Point(X, Y);
}
public void random_points()
{
while (n < 65)
{
points[n] = new PictureBox
{
BackColor = Color.Blue,
Size = new Size(10, 10),
Visible = true,
Location = generateXY(),
};
points[n].Show();
this.Controls.Add(points[n]);
points[n].Refresh();
n++;
}
this.Refresh();
}
public MajorForm()
{
InitializeComponent();
timer.Stop();
}
private void timer_Tick(object sender, EventArgs e)
{
}
private void MajorForm_Load(object sender, EventArgs e)
{
random_points();
}
}
}
random_points()
перенести в обработчик событияForm.Load