In my code, every time button1 is pressed an instance of a picturebox called NOT is spawned in a panel. When the image is clicked and held on it can be dragged around. My question is every time button1 is pressed I want another pictureBox of the same properties to be created so that theoretically I could press button1 all day and drag around as many NOT picturebox objects around as I want. So far once the button is pressed only one instance of NOT is created and another cannot be spawned. So essentially how do make new unique instances of NOT every time button1 is pressed.
public Form1()
{
InitializeComponent();
Drag();
}
private void button1_Click(object sender, EventArgs e)
{
spawnGate("not");
}
PictureBox NOT = new PictureBox();
private Point startPoint = new Point();
public void Drag()
{
NOT.MouseDown += (ss, ee) =>
{
if (ee.Button == System.Windows.Forms.MouseButtons.Left)
{
startPoint = Control.MousePosition;
}
};
NOT.MouseMove += (ss, ee) =>
{
if (ee.Button == System.Windows.Forms.MouseButtons.Left)
{
Point temp = Control.MousePosition;
Point res = new Point(startPoint.X - temp.X, startPoint.Y - temp.Y);
NOT.Location = new Point(NOT.Location.X - res.X, NOT.Location.Y - res.Y);
startPoint = temp;
}
};
}
public void spawnGate(string type)
{
switch (type)
{
case "not":
NOT.Width = 100;
NOT.Height = 50;
NOT.Image = Properties.Resources.Not_gate;
NOT.SizeMode = PictureBoxSizeMode.Zoom;
workspace.Controls.Add(NOT);
break;
}
}
}