Click to See Complete Forum and Search --> : User Control creation problem


December 14th, 1999, 11:41 PM
We have developed a user control in VB 5.0 which uses imagelists present in the form. The imagelist in the form are not created by the time the user control is created. We have tried to work around this by doing the user control intializations in a timer event. Is is possible to create the image list same time as our control. Foe Ex. The Comctl toolbar and its associated image list.

czimmerman
December 15th, 1999, 05:15 PM
If you need the imagelists at the time of usercontrol_initialize, you probably need to include the image list as part of the usercontrol itself.

Charlie Zimmerman
http://www.freevbcode.com

December 15th, 1999, 11:24 PM
We have built an OCX control which is very similar to toolbar.
When you place this control on your VB form then you see around 5 default buttons that come automatically.
After placing this control the user can add new buttons next to that already present.
The user can attach the images from any other imagelists on the form for the added buttons.
Next time the user loads the form, the OCX control is displayed with the default buttons + newly added buttons (added by user previously).
The problem is in the above step.
Since the images for the newly added buttons are in a different control (Imagelist on the form) and this control is not created during the time our OCX control is loaded, it gives a run time error while adding images.
To solve the above problem, we have put a timer event in the OCX control for interval of 5 ms and then adding the images.
Is it possible to solve this problem in a better way ?
Is it possibe to make it behave in a similar way to comctl toolbar and its associated Imagelist.

The constituent controls in our OCX are
1. Comctl Toolbar
2. Comctl Imagelist.

The above imagelist holds the images for the default buttons.
When user adds new buttons and attaches images to it from someother imagelist, we add the images to comctl Imagelist in the OCX.
Since runtime addition of images to the Imagelist are not stored in thr frx file.
we have to add the images to our Comctl Imagelist from the VB form imagelist everytime the OCX is created.

czimmerman
December 15th, 1999, 11:48 PM
Try the following:

1. When the user selects a new image, save it to a file, by creating a reference to the listimage's picture object and then calling the SavePicture method.

2. Keep track of all the files saved in the registry or .ini file.

3. When the .ocx is initialized, call the loadpicture method to load each file, then add them to the imagelist using Imagelist.ListImages.Add.

Of course, this depends on the user not moving the files around, but you can check for this before loading.