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!!!!!!!!!!!!!!!
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.
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.
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?
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.