ArrayList of PictureBoxes
-
What I am trying to do is create a new picturebox everytime you left click on the screen and delete the one you are on when you left click on one. This is the code I have. if (c == panel1) { if (e.Button == MouseButtons.Left) { //Get picturebox from unUsedBoxes to Create a new box int position = unUsedBoxes.Count - 1; if (position >= 0) { System.Windows.Forms.PictureBox p = (PictureBox)unUsedBoxes[position]; unUsedBoxes.RemoveAt(position); usedBoxes.Add(p); p.Location = new System.Drawing.Point(e.X, e.Y); p.Size = new System.Drawing.Size(100, 50); p.Show(); p.MouseDown += new MouseEventHandler(mouseDown); p.MouseUp += new MouseEventHandler(mouseUp); p.MouseMove += new MouseEventHandler(mouseMove); } else { MessageBox.Show("You have exceeded the maximum number of selections", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { if (e.Button == MouseButtons.Right) { //Delete box usedBoxes.Remove(c); unUsedBoxes.Add(c); panel1.Dispose(); } } } the code compiles but the picturebox is never created.
-
What I am trying to do is create a new picturebox everytime you left click on the screen and delete the one you are on when you left click on one. This is the code I have. if (c == panel1) { if (e.Button == MouseButtons.Left) { //Get picturebox from unUsedBoxes to Create a new box int position = unUsedBoxes.Count - 1; if (position >= 0) { System.Windows.Forms.PictureBox p = (PictureBox)unUsedBoxes[position]; unUsedBoxes.RemoveAt(position); usedBoxes.Add(p); p.Location = new System.Drawing.Point(e.X, e.Y); p.Size = new System.Drawing.Size(100, 50); p.Show(); p.MouseDown += new MouseEventHandler(mouseDown); p.MouseUp += new MouseEventHandler(mouseUp); p.MouseMove += new MouseEventHandler(mouseMove); } else { MessageBox.Show("You have exceeded the maximum number of selections", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { if (e.Button == MouseButtons.Right) { //Delete box usedBoxes.Remove(c); unUsedBoxes.Add(c); panel1.Dispose(); } } } the code compiles but the picturebox is never created.
A control is most useful when you add it to some container...
Luc Pattyn [My Articles] [Forum Guidelines]
-
A control is most useful when you add it to some container...
Luc Pattyn [My Articles] [Forum Guidelines]
I already have this code in the Designer this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.pictureBox1.Location = new System.Drawing.Point(0, 0); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(100, 50); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; And this code in the On Load usedBoxes = new ArrayList(); unUsedBoxes = new ArrayList(); unUsedBoxes.Add(pictureBox1); do I need to specify more than that a parent?
-
I already have this code in the Designer this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.pictureBox1.Location = new System.Drawing.Point(0, 0); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(100, 50); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; And this code in the On Load usedBoxes = new ArrayList(); unUsedBoxes = new ArrayList(); unUsedBoxes.Add(pictureBox1); do I need to specify more than that a parent?
a control only "works" in a UI when added to the form's hierarchy of controls, as in myForm.Controls.Add(myControl) check this in the documentation, and in the code generated by Visual Studio's Designer ! :)
Luc Pattyn [My Articles] [Forum Guidelines]