Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Raise Event issue with dynamic controls

Status
Not open for further replies.

marble

Programmer
Mar 17, 2001
22
0
0
CA
Hi all,

I have a class that add or remove several picture boxes (up to 49) dynamically to a form, this works great.

The issue is that I can only raise events for the last picturebox created on my form.


Private WithEvents PBox As PictureBox

'is the declaration for the picture box, all the pictureboxes are set in a loop with the following code

Set PBox = mCallingForm.Controls.Add("vb.picturebox", "PicBox" & irow & icol, mCallingForm)

irow and icol are counters that will increment when the row and columns change. This works great!


private PBox_Click()
msgobx("I'm picturebox " & PBox.name")
end sub


How do I get the events of the other picture boxes?

Thankyou in advance,

Marble
 
I asked a similar question in thread222-546126 so that may be worth a look.

Also rather that dynamically adding the picturebox to the controls collection, maybe a control array may be more appropriate.



Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Mat,

Thankyou for the replay, I have read your thread and I am a little confused on which approach is best. Can I get your opinion in what I would like to do...

I am trying to create an interface to add 2 types of controls.

1st control is a picture box
2nd control is a viewing control for certain cameras

I would like to populate the form (picture boxes), then allow a user to add the second control to any number of pictureboxes.

I was hoping to do this dynamically, I have created my picturebox class and this class adds , removes the picture boxes to a form. This works great except for the events.

I know that I can added them to the form (arrays) and load a new control when needed, but I was trying to make this more maintainable.

Any opinions would be greatly appeciated.

Thanks in advance,

Marble
 
Use a (class) collection, and create/add a new class instance for each picture box created. Then each control has it's own class and set of events.

When you reference a control, do it then like this:

colPict(1).myPictClass.PictBox
where PictBox is a public property and references the PBox private property.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top