By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,485 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,485 IT Pros & Developers. It's quick & easy.

Use an array or collection as a usercontrol property?

P: n/a
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

Nov 20 '05 #1
Share this Question
Share on Google+
15 Replies


P: n/a
Cor
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
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

Nov 20 '05 #2

P: n/a
There has to be a way to make it appear as a collection like VB.Net's built
in controls do it.

"Cor" <no*@non.com> wrote in message
news:Op**************@TK2MSFTNGP09.phx.gbl...
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
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


Nov 20 '05 #3

P: n/a
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!

: )
"Noozer" <po********@127.0.0.1> wrote in message
news:GUxIb.877073$pl3.338306@pd7tw3no...
There has to be a way to make it appear as a collection like VB.Net's built in controls do it.

"Cor" <no*@non.com> wrote in message
news:Op**************@TK2MSFTNGP09.phx.gbl...
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
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



Nov 20 '05 #4

P: n/a
Cor
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)
///

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!

: )

Nov 20 '05 #5

P: n/a
* "Noozer" <po********@127.0.0.1> scripsit:
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.
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


--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

P: n/a
And this will show up as a Collection in the Properties page of my
control???

"Cor" <no*@non.com> wrote in message
news:Of**************@TK2MSFTNGP12.phx.gbl...
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)
///

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!

: )


Nov 20 '05 #7

P: n/a
Cor
??
How do you set the index?
...
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.

Nov 20 '05 #8

P: n/a
Cor
Hi Noozer,

Did you try it?

Cor
And this will show up as a Collection in the Properties page of my
control???

Nov 20 '05 #9

P: n/a
* "Cor" <no*@non.com> scripsit:
??
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(...)
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #10

P: n/a
Cor
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

\\\
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(...)
///

--

Nov 20 '05 #11

P: n/a
Cor
Hi Noozer,

Look at the answer from Herfried,
It is better,

Cor
Nov 20 '05 #12

P: n/a
* "Cor" <no*@non.com> scripsit:
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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #13

P: n/a
> \\\
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(...)
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Thanks Herfried!

One question though... When doing this, the property doesn't appear in the
properties list in the IDE at design time. This means I can't add or edit
the images at design time.

My code below seems a bit closer as it appears in the properties list, but
it just provides a general collection (hashtable actually) of system objects
instead of image objects.

dim hImages as Hashtable
....
'Allow edit images in hash table through IDE Collection Editor
Public Property hIma() As Hashtable
Get
Return hImages
End Get
Set(ByVal Value As Hashtable)
hImages = Value
End Set
End Property
....
'Remove an image from hashtable
Public Function hImaRemove(ByVal key As String)
If hImages.Contains(key) Then 'If this key exists...
hImages.Remove(key) '...remove image from hashtable and
Return True '...return TRUE
Else
Return False '..otherwise return FALSE
End If
End Function
....
'Add image to hashtable
Public Sub hImaAdd(ByVal [Image] As Image, ByVal key As String)
If hImages.Contains(key) Then 'If key exists...
hImages.Remove(key) '...remove it first.
End If
hImages.Add([Image], key) 'Add new image
End Sub
Nov 20 '05 #14

P: n/a
* "Noozer" <po********@127.0.0.1> scripsit:
One question though... When doing this, the property doesn't appear in the
properties list in the IDE at design time. This means I can't add or edit
the images at design time.


I am not familiar with this topic, but I am sure you will get a solution
in this group:

<news://news.microsoft.com/microsoft.public.dotnet.framework.windowsforms.des igntime>

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #15

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OZ***************@tk2msftngp13.phx.gbl...
* "Noozer" <po********@127.0.0.1> scripsit:
One question though... When doing this, the property doesn't appear in the properties list in the IDE at design time. This means I can't add or edit the images at design time.
I am not familiar with this topic, but I am sure you will get a solution
in this group:

<news://news.microsoft.com/microsoft....indowsforms.de
signtime>
--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>


Thanks! Moving to the new group.
Nov 20 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.