Привет
Есть метод panel1_Paint() который при запуске програмы запускается несколько раз(4 раза а потом ошибка)
вот код:
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;
namespace task3_cSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private const int CS_DROPSHADOW = 0x20000;
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ClassStyle |= CS_DROPSHADOW;
return cp;
}
}
private void Exit_Click(object sender, EventArgs e)
{
ActiveForm.Close();
}
private void Maximized_Click(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Maximized) WindowState = FormWindowState.Normal;
else WindowState = FormWindowState.Maximized;
}
private void Minimize_Click_1(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
}
private Point mouseOffset;
private bool isMouseDown = false;
private void ControlForm_MouseDown(object sender, MouseEventArgs e)
{
this.Capture = false;
Message m = Message.Create(Handle, 0xa1, new IntPtr(2), IntPtr.Zero);
WndProc(ref m);
}
private void Exit_MouseEnter(object sender, EventArgs e)
{
Exit.BackColor = Color.Red;
}
private void Exit_MouseLeave(object sender, EventArgs e)
{
Exit.BackColor = Color.FromArgb(53, 54, 58);
}
private void Paired_pictures_Draw(object sender, EventArgs e)
{
}
private void Paired_pictures_Draw(object sender, PaintEventArgs e)
{
}
Image[] img = new Image[]
{
Properties.Resources._1,
Properties.Resources._2,
Properties.Resources._3,
Properties.Resources._4,
Properties.Resources._5,
Properties.Resources._6,
Properties.Resources._7,
Properties.Resources._8,
Properties.Resources._9,
Properties.Resources._10,
Properties.Resources._11,
Properties.Resources._12
};
//static int QuantityWidth = 4;
//static int QuantityHeight = 4;
int QuantityItem = 16;
private void panel1_Paint(object sender, PaintEventArgs e)
{
Console.WriteLine($"{1}");
Label l = new Label();
PictureBox p1 = (PictureBox)game1.Controls[0];
l.Text = p1.ToString();
first.Controls.Add(p1);
/*foreach (PictureBox p in game1.Controls)
{
// ...
}*/
for (int i = 0; i < QuantityItem/2; i++)
{
for (int j = 0; j < 2; j++)
{
Random rand = new Random();
int r = rand.Next(0, QuantityItem);
//Console.WriteLine($"{i}");
setImg((PictureBox)game1.Controls[r], i);
//Console.WriteLine($"{r} {i}");
}
}
}
void setImg(PictureBox p, int id)
{
p.Image = img[id];
//Console.WriteLine($"true");
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
Само событие есть только у одной панели
Зарание спасибо!)