Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ArrayList of PictureBoxes

ArrayList of PictureBoxes

Scheduled Pinned Locked Moved C#
graphicshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aei_totten
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • A aei_totten

      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.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      A control is most useful when you add it to some container...

      Luc Pattyn [My Articles] [Forum Guidelines]

      A 1 Reply Last reply
      0
      • L Luc Pattyn

        A control is most useful when you add it to some container...

        Luc Pattyn [My Articles] [Forum Guidelines]

        A Offline
        A Offline
        aei_totten
        wrote on last edited by
        #3

        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?

        L 1 Reply Last reply
        0
        • A aei_totten

          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?

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          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]

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups