473,414 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Use an array or collection as a usercontrol property?

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
15 5850
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
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
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
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
* "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
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
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
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
* "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
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
Cor
Hi Noozer,

Look at the answer from Herfried,
It is better,

Cor
Nov 20 '05 #12
* "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
> \\\
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
* "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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Julian | last post by:
Hi, I am using PHP 4 with classes but I have come across a slight problem... I can't declare an array as a property of a class, ie, class clTest { var $a; clTest()
3
by: Marc L'Ecuyer | last post by:
Hi, I have a collection class derived from CollectionBase. This collection can add items of my class MyItem. In my class MyItem, I have a Selected property. When this property is set to true, I...
3
by: Faustino Dina | last post by:
Hi, The following code is from an article published in Informit.com at http://www.informit.com/guides/content.asp?g=dotnet&seqNum=142. The problem is the author says it is not a good idea to...
3
by: Iain | last post by:
Hi I have page (testCal.aspx) that contains a usercontrol (custCalendar.ascx) - see below signature for code. The UC contains a linkbutton which which when clicked, posts back and displays a...
3
by: Gary Kahrau | last post by:
I hope this is a simple question. I have a number of usercontrols placed on a form. The usercontrol has a public property (DispMachine) within it. When looping through the main form controls, I...
3
by: Ant | last post by:
Hi, I'm using the tag property of the Treenode object to store an string array containing some values. I can assign it to the Tag but when I try to retrieve values from it I get an error:...
1
by: kferron | last post by:
if i wanted to expose a property on a usercontrol that basically would work like the way the validators work with the ControlToValidate property, whats a reliable way of finding the correct control...
1
by: 12jumper | last post by:
Hi All :) I've created an UserControl, which has a couple of properties that are collections (generic lists of some objects). It would be nice, if control refreshed each time I add a new item to...
9
by: Johnny Jörgensen | last post by:
Hi y'all I've got a custom control that is inherited from a normal TextBox. To that, I've added a new property that I call "Units", Which is a collection class containing members of a "Unit"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.