Bubbling properties in User Controls.....

  • Thread starter Thread starter Jim Hubbard
  • Start date Start date
J

Jim Hubbard

If I create a usercontrol that is a tab with a webbrowser control on it, by
default the new control exposes no properties of the tab or webbrowser
control.

What is the easiest way to bubble the public properties, methods and
functions up to the usercontrol interface?
 
For a UserControl, you can use any legal names you want for properties and
methods. For inherited controls you would use the Shadows keyword to do your
own implementation of an underlying property or method.

For a UserControl, it would look something like this:

Public Property ContainedObjectSomeProperty() As String
Get
Return Me.ContainedObject.SomeProperty
End Get
Set(ByVal Value As String)
Me.ContainedObject.SomeProperty = Value
End Set
End Property

Public Function ContainedObjectMethod(ByVal Param1 As Int32) As String
Return Me.ContainedObject.ContainedObjectMethod(Param1)
End Function
 
I guess what I am looking for is a way to inherit the public methods and
properties, etc. that allows me to use something like intellisense or the
drop downs to access the underlying methods, properties, etc..

Having to re-type every method, property, etc. seems like a waste of
time.....seems like I'm missing something here.
 
You could do a work around. It could be specific to a given UserControl, or
a more generic function that works from inside the UserControl. In the
(simpler) first case,
you could just loop through the controls of the UserControl from the hosting
form's Load event and use directcast to make form-wide references (or
whatever scope you need) of the contained controls. You would need nested
loops to get into a container control such as the TabControl.

At the more generic level, you could create a GetControls method that
operates from within the UserControl. Again, you would have to use nested
loops where you have containers. A hashtable would be a good return value
type, and you could create a naming scheme for the keys to help in
identifying the controls at the form level. Using the hashtable.containskey
you should be able to easily get a reference to the contained controls from
the form.

As an alternative, you could inherit directly from the container control,
then apply the same ideas above. At least your control would automatically
have the intellisense access you want at the top level. That would take one
layer out as you probe for the contained objects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top