Use an array or collection as a usercontrol property?

  • Thread starter Thread starter Noozer
  • Start date Start date
N

Noozer

Trying to specify a single public property on my user control to hold three
different images. I figure out how to do this and Google searches are not
helping. (I probably am not searching on the right terms.)

My sample below is using an array of images, but I cannot specify more than
one parameter in the SET statement. I'm not sure how I'd change this to use
a collection of images.

....
Private iImages(2) as image 'Holds three images
....

'Set/Return image for particular state
Public Property image(ByVal index As Integer) As image
Get
Return iImages(index)
End Get
Set(ByVal index as Integer, ByVal Value As image) '<---Doesn't work. How
do I specify an index
iImages(index) = Value
If iIndex = index Then 'If changing image for currently displayed image,
apply it to display
picImage.Image = Value
End If
End Set
End Property
 
Hi Noozer,

I think you have to make 2 properties,
one to set your index and one for the image you want to have returned
Or some functions

I would choose for the 2 properties and then the image is readonly

I hope this helps?

Cor
 
There has to be a way to make it appear as a collection like VB.Net's built
in controls do it.
 
FWIW... I sortof have the functionality by defining my property as an
imagelist.

Still not what I want though as I need a collection of individual images
that could be different sizes.

I know I'm missing something very basic here and I just can't nail it down!
Talk about frustrating!

: )
 
Hi Noozer,

Yes I think you mis something basic, I tried to tell you

I did type it here (Roughly not tested, see it as pseudo, altough I think it
is complete)

2 samples as propertys and as function

I hope this was what you where looking for?

Cor

\\\
Public Class Noozer
Private Shared iImages(2) as image 'Holds three images
Private Shared pIndex as integer ' holds the index
'Set/Return image for particular state
Public shared Read Only Property myImage As image
Get
Return iImages(pImage)
End Get
End Property
Public shared Property i as integer
Get
Return pIndex
End Get
Set (byVal Value as integer)
pIndex = Value
End Set
End Property

'to set and get this this
Noozer.index = 1
myImage = Noozer.MyImage

'As a function
Public shared function MyImage (byval i as integer) as image
return iImages(i)
End function

'to get this
myImage = Noozer.myimage(1)
///
 
* "Noozer said:
Trying to specify a single public property on my user control to hold three
different images. I figure out how to do this and Google searches are not
helping. (I probably am not searching on the right terms.)

My sample below is using an array of images, but I cannot specify more than
one parameter in the SET statement. I'm not sure how I'd change this to use
a collection of images.

...
Private iImages(2) as image 'Holds three images
...

'Set/Return image for particular state
Public Property image(ByVal index As Integer) As image
Get
Return iImages(index)
End Get
Set(ByVal index as Integer, ByVal Value As image) '<---Doesn't work. How

Just skip the index parameter above.
 
* "Cor said:
??
How do you set the index?

\\\
Private m_Images() As Image ' ...

Public Property Images(ByVal Index As Integer) As Image
Get
Return m_Images(Index)
End Get
Set(ByVal Value As Image)
m_Images(Index) = Value
End Set
End Property
///

Usage

\\\
Dim x As New ...
x.Images(2) = Image.FromFile(...)
///
 
Hi Herfried,

A lot of thanks from me today for you,

Once I had a problem doing this,
I did not know why so I never did it and made automaticly a function from
it.
(I shall start to investigate properties something more I think, although
they willbey change again)

This is even better I think in this case, but that is a detail

Private m_Images() As Image ' ...
Public ReadOnly Property Images(ByVal Index As Integer) As Image
Get
Return m_Images(Index)
End Get

Cor
 
* "Cor said:
Once I had a problem doing this,
I did not know why so I never did it and made automaticly a function from
it.
(I shall start to investigate properties something more I think, although
they willbey change again)

Parameters defined in the 'Property' are visible to the "getter" and
"setter" too. VB.NET allows parameterized properties which is sometimes
really useful.
This is even better I think in this case, but that is a detail

Private m_Images() As Image ' ...
Public ReadOnly Property Images(ByVal Index As Integer) As Image
Get
Return m_Images(Index)
End Get

ACK.
 
Back
Top