-
Jan 1st, 2016, 08:55 PM
#1
Thread Starter
Lively Member
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!!!!!!!!!!!!!!!
-
Jan 1st, 2016, 09:19 PM
#2
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.
-
Jan 2nd, 2016, 06:28 AM
#3
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.
-
Jan 2nd, 2016, 08:30 PM
#4
Thread Starter
Lively Member
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?
-
Jan 2nd, 2016, 09:20 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|