Question vb 2008: usercontrol controls exposure, methods, properties?

Hopworks

Member
Joined
Mar 31, 2011
Messages
10
Programming Experience
5-10
I'm writing a suite of vb 2008 express applications supported by MySQL databases and needed a control for selecting a date sorted by four week periods. The supplied monthcalendar wasn't right for this so I decided to try my hand at creating a user control.

In this control, I dynamically add controls and assign events to them. On my main form, I dynamically add the user control and everything works just fine.

My problem now is where to go next. I'm unclear as to how to expose the dynamically created controls inside the user control to the main form, how to generate an event in the main form when I click on a dynamically created control inside the user control, or how I can access those controls properties in the user control from the main form.

This matters because I plan to use this period calendar control across multiple forms and want to populate the text properties of the user control controls from those forms, because the data I want to display depends on the forms that uses the user control.

I can work around that by accessing the MySQL database inside the user control to grab text data for the created controls, but then again, the user control needs to know what scenario is desired to be able to pick the correct table, etc.

I didn't post any code because I'm not asking someone to offer code as a bandaid fix. I'm just looking for user control examples or something in MSDN I can't seem to find. I googled this for a week and all I find is how to create an analog clock user control, but nothing in-depth on coding a fully interactive user control.
Period Calendar UserControl.jpg


Thank you so much for your time!

Hop
 
Last edited:
Let's say that you have multiple Buttons inside a UserControl. The UserControl itself would handle the Click event of each Button. It would then raise its own event, e.g. ButtonClicked. Just as with all events, the 'e' parameter would pass the required data to the event handler. That might be the Button itself, the Text of the Button, the index or whatever is appropriate.

The same goes for properties and methods. The UserControl exposes all and only the data require by the parent to interact with the children. That might be a collection of child controls, or it might be a collection of Strings where each item is the Text of a child. It might be something else entirely, depending on the circumstances, but it's likely to be indexed regardless.
 
Back
Top