[RESOLVED] Passing ImageList between forms
Hi,
I have two forms frmMain and frmUsers.
frmMain has an ImageList, and I fill that list with pics from file when program starts.
However I need to use the pics from the ImageList on my other form.
How can I use the ImageList from frmMain in my other form?
Re: Passing ImageList between forms
if you are using VB 2005, then you should be able to access it through the default instance of frmMain. If you are not, and using a variable instance for each form, you could simply pass the imagelist to frmUsers when you create it
to do that you would either create a public property in frmUsers to accept the image list
(sorry this code is all freehand...)
VB Code:
Private _MyImageList as ImageList
Public Property MyImageList() as ImageList
Get
return _MyImageList
End Get
Set(value as imagelist)
_MyImageList = value
end set
end property
if the image list being in frmUsers is ALWAYS needed, you may want to actually add it to the constructor (the New sub) instead of making it a public property.. that way you can't create an instance of the form without passing it an image list...
Re: Passing ImageList between forms
you can reference a variable from another form by passing it through subroutines: like this:
VB Code:
Sub users(ByVal imglst As ImageList)
End Sub
then reference this sub from frmMain:
frmUsers.users(imagelist1)
your imagelist will then be available on frmUsers.
Re: Passing ImageList between forms
Thanks,
I'll did it passing the ImageList in the form constructor (just as any variable) and that seems to work.