[VB.NET] Creating a PictureBox Collection
Solved
Orbital38
Posted messages
71
Registration date
Status
Member
Last intervention
-
Orbital38 Posted messages 71 Registration date Status Member Last intervention -
Orbital38 Posted messages 71 Registration date Status Member Last intervention -
Hello,
I wanted to know how to create a collection of PictureBox.
Actually, I'm trying to retrieve the first item of my collection (a PictureBox) in order to change its image. However, I'm encountering late binding errors since a standard collection is of type Object.
Currently, I'm doing this:
I'm creating my PictureBoxes and each time I do:
Later in the code, I want to initialize an image (the first one in my collection). I've resorted to using the Name property to hack something together:
But I find it ugly and I would like to be able to do something like:
But here, VS gives me a collection of Object with Collect_menu. I wanted to know if we can define a type for a collection and what the syntax for that would be.
Or if there's something else for a collection of PictureBox, like ImageList for a collection of Images.
Thank you! =)
Configuration: Windows / Firefox 40.0
I wanted to know how to create a collection of PictureBox.
Actually, I'm trying to retrieve the first item of my collection (a PictureBox) in order to change its image. However, I'm encountering late binding errors since a standard collection is of type Object.
Currently, I'm doing this:
Public Collect As Collection Public Pic_ppl As Classe1
Collect = New Collection
I'm creating my PictureBoxes and each time I do:
Pic_ppl = New Classe1 Pic_ppl.btn = PictureBoxCs Collect.Add(Pic_ppl.btn)
Later in the code, I want to initialize an image (the first one in my collection). I've resorted to using the Name property to hack something together:
For Each Ctrl As System.Windows.Forms.PictureBox In Collect_menu.OfType(Of PictureBox).Where(Function(picBox) picBox.Name = "Pic1") Ctrl.Image = Outils.ImageList1.Images.Item(0) Next Ctrl
But I find it ugly and I would like to be able to do something like:
Collect.Item(1).Image = ImageList1.Images.Item(0)
But here, VS gives me a collection of Object with Collect_menu. I wanted to know if we can define a type for a collection and what the syntax for that would be.
Or if there's something else for a collection of PictureBox, like ImageList for a collection of Images.
Thank you! =)
Configuration: Windows / Firefox 40.0
Related links:
- changing language in vb.net
- Retrieve the result of a SELECT (VB.net)
- VB.net program does not start
- Éteindre le PC avec VB.NET peut être effectué en utilisant la commande suivante : ```vb Process.Start("shutdown", "/s /t 0") ```
- I cannot install .NET Framework 4.8 on Windows 10
- Connecting to MySQL from VB.net version 8.0.28
Well, sorry for bringing up subjects for nothing like that. :/
Just for my knowledge, what is the difference between a collection and a list? Is it the key indexing? Or does the collection offer something more?
Thank you anyway. ^^
The "collection" of the framework is a simplified declaration (not exact, but that's the idea) List(Of Object)
Otherwise, in the Collection.Generic namespace, you also have dictionaries, sorted lists, stacks, queues, ...
So the collections are more general to avoid being limited and have plenty of associated methods. It’s the kind of thing that can confuse someone like me who doesn’t know anything about it. Got it!
Thanks anyway. My Form is taking shape!