Get reference to usercontrol's parent

  • Thread starter Thread starter Tom
  • Start date Start date
T

Tom

This seems like a dumb question, but here goes: In my own VB.NET user
control, how do I gain access to the user controls parent? (i.e. the form
that is hosting the user control) For instance, in the control I want to set
the focus back to the main form that has the user control. Most other
classes/controls seem to have a Parent but not a user control.

I could, of course, pass a reference of the main form to the user control,
but this seems like overkill. Any other way? Thanks....

Tom
 
Tom said:
In my own VB.NET user control, how do I gain access to the
user controls parent?

Would you believe the [UserContrl].Parent property?

The FindForm() method will also get you the Form on which the
control appears, which is *not* necessarily the same thing.

HTH,
Phill W.
 
Tom said:
This seems like a dumb question, but here goes: In my own VB.NET user
control, how do I gain access to the user controls parent? (i.e. the form
that is hosting the user control) For instance, in the control I want to
set
the focus back to the main form that has the user control. Most other
classes/controls seem to have a Parent but not a user control.

'UserControl' inherits from 'Control' and thus has a 'Parent' property and a
'FindForm' method. In addition to that, it has a 'Container' property.
 
Aha, this may explain it. I mis-spoke... This is a non-visual control, i.e.
a componet, so instead I inherit from System.ComponentModel.Component,
rather than user control.

So, there is probably no way to get the parent directly from here, is there?
Again, I want this to be a non-visual control (one that shows up in the
developer 'tray area' like a menu or image control does)...

Tom
 
Phil: As I mentioned to Herfried:

Aha, this may explain it. I mis-spoke... This is a non-visual control, i.e.
a componet, so instead I inherit from System.ComponentModel.Component,
rather than user control.

So, there is probably no way to get the parent directly from here, is there?
Again, I want this to be a non-visual control (one that shows up in the
developer 'tray area' like a menu or image control does)...

Tom

Phill. W said:
Tom said:
In my own VB.NET user control, how do I gain access to the
user controls parent?

Would you believe the [UserContrl].Parent property?

The FindForm() method will also get you the Form on which the
control appears, which is *not* necessarily the same thing.

HTH,
Phill W.
 
Tom said:
Aha, this may explain it. I mis-spoke... This is a non-visual control,
i.e.
a componet, so instead I inherit from System.ComponentModel.Component,
rather than user control.

So, there is probably no way to get the parent directly from here, is
there?
Again, I want this to be a non-visual control (one that shows up in the
developer 'tray area' like a menu or image control does)...

Components are typically placed in the components tray in VS.NET. You can
use a component's 'Container' property to get the container it resides in.
The components 'Site' property might be of interest too.
 
I have the same problem, I have a form on which I drag a
self made component, it appears under the separater below the form.
When I call me.Container or me.Site in the component they return nothing
 

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