VS 2013 VB 2013 Creating New Object And Moving Its Location From Another Object In Its Class-VBForums
Results 1 to 5 of 5

Thread: VB 2013 Creating New Object And Moving Its Location From Another Object In Its Class

  1. #1

    Thread Starter
    Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Michigan
    Posts
    43

    Question VB 2013 Creating New Object And Moving Its Location From Another Object In Its Class

    I am currently working on a project where I programmed a button to create a new picture.

    Dim newpicture As New PictureBox
    newpicture.Width = 75
    newpicture.Height = 75
    newpicture.Location = New Point(30, 30)


    However, now later in my project, I am in need of changing the new object's location.
    How can I do this easily? Is there a way that I can have the new objects be added to the class?

    -BTW I have to keep the newly added objects because more than just one is added in my project.
    Thank you!!!!!!!!!!!!!!!

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,192

    Re: VB 2013 Creating New Object And Moving Its Location From Another Object In Its Cl

    FYI - You can keep the formatting of your code by using code tags:
    [CODE]Dim newpicture As New PictureBox
    newpicture.Width = 75
    newpicture.Height = 75
    newpicture.Location = New Point(30, 30)[/CODE]

    Will render like such:
    Code:
    Dim newpicture As New PictureBox
    newpicture.Width = 75
    newpicture.Height = 75
    newpicture.Location = New Point(30, 30)
    As far as setting the dynamically created object's property, you'll need to reference the object somehow. This can be done by adding a name and using the Find method on a ControlCollection.

  3. #3
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    4,033

    Re: VB 2013 Creating New Object And Moving Its Location From Another Object In Its Cl

    Personally, I would just maintain my own list of Picturebox, and add the pictureboxes to the list when I created them, but then I tend to access things by an index, not by name.

  4. #4

    Thread Starter
    Member kshadow22's Avatar
    Join Date
    Dec 2014
    Location
    Michigan
    Posts
    43

    Re: VB 2013 Creating New Object And Moving Its Location From Another Object In Its Cl

    Thank you a lot! Everything you've told me sounds like what I am in need of. But What would the codes look like to do that?

  5. #5
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    31,096

    Re: VB 2013 Creating New Object And Moving Its Location From Another Object In Its Cl

    A List(of Picturebox) at form level is probably what Passel is describing. An alternative would be a Dictionary(of something, Picturebox). In the case of the Dictionary, you can use whatever you want as the key, whether an integer, a string, an Enum value, or whatever.
    My usual boring signature: Nothing

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.