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. Problem with ByValue Parameters

Problem with ByValue Parameters

Scheduled Pinned Locked Moved C#
questionhelp
7 Posts 3 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.
  • S Offline
    S Offline
    Seraphin
    wrote on last edited by
    #1

    At start I have a picturebox generated by Runtime, image is already initialized. The name of the pbox is "picBoxDoubles_object1". Now I have an ArrayList and want add this picturebox. public void MovePicToDest(PicBoxDoubles pbd) { ArrayList arr = new ArrayList(); arr.Add(pbd); arr.Clear(); <----------- } If arr.Clear is executed, the picturebox disappears from the desktop. Is "pbd" not a parameter ByValue? So it seems, that the real object was added not a copy. How can I solve this one?

    K 1 Reply Last reply
    0
    • S Seraphin

      At start I have a picturebox generated by Runtime, image is already initialized. The name of the pbox is "picBoxDoubles_object1". Now I have an ArrayList and want add this picturebox. public void MovePicToDest(PicBoxDoubles pbd) { ArrayList arr = new ArrayList(); arr.Add(pbd); arr.Clear(); <----------- } If arr.Clear is executed, the picturebox disappears from the desktop. Is "pbd" not a parameter ByValue? So it seems, that the real object was added not a copy. How can I solve this one?

      K Offline
      K Offline
      KaptinKrunch
      wrote on last edited by
      #2

      Change the method to accept PictureBox type. public void MovePicDest(PictureBox pb) { ArrayList arr = new ArrayList(); arr.Add(pb); //Now if ArrayList.Clear is called; it should clear the arraylist and not remove your object. arr.Clear(); }

      S 1 Reply Last reply
      0
      • K KaptinKrunch

        Change the method to accept PictureBox type. public void MovePicDest(PictureBox pb) { ArrayList arr = new ArrayList(); arr.Add(pb); //Now if ArrayList.Clear is called; it should clear the arraylist and not remove your object. arr.Clear(); }

        S Offline
        S Offline
        Seraphin
        wrote on last edited by
        #3

        PicBoxDoubles has Inheritance to PictureBox, so if I am change the parameter it still doesn't work.

        K 1 Reply Last reply
        0
        • S Seraphin

          PicBoxDoubles has Inheritance to PictureBox, so if I am change the parameter it still doesn't work.

          K Offline
          K Offline
          KaptinKrunch
          wrote on last edited by
          #4

          What is the reason behind adding the picturebox to the ArrayList?

          S 1 Reply Last reply
          0
          • K KaptinKrunch

            What is the reason behind adding the picturebox to the ArrayList?

            S Offline
            S Offline
            Seraphin
            wrote on last edited by
            #5

            The application has two big Pictureboxes A and B. "A" has many child objects(PictureBoxes) and if you click on one of these, they are copied to "B". Actually they are transfered during this problem. It should stay in A and make a copy to B.

            S 1 Reply Last reply
            0
            • S Seraphin

              The application has two big Pictureboxes A and B. "A" has many child objects(PictureBoxes) and if you click on one of these, they are copied to "B". Actually they are transfered during this problem. It should stay in A and make a copy to B.

              S Offline
              S Offline
              Seraphin
              wrote on last edited by
              #6

              I made a new object of this class and copied each attribute. This works, but the inherited Picturebox has more than 80 new attributes. Not a real good solution. I need to know how to copy objects.

              T 1 Reply Last reply
              0
              • S Seraphin

                I made a new object of this class and copied each attribute. This works, but the inherited Picturebox has more than 80 new attributes. Not a real good solution. I need to know how to copy objects.

                T Offline
                T Offline
                tommazzo
                wrote on last edited by
                #7

                You could implement the IClonable interface in your PictureBox class. This interface is used to create a copy of an object, but you would still have to write the attribute copying code in there.

                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