Getting Form a component is in.

J

JackRazz

Is there a way to get a components parent form from within the component?

Thanks - JackRazz
 
J

JackRazz

Richard, I wish it were that easy. a component doesn't have a parent. the only hope
would be from the components list, but I don't think that a form is added to the
component list. I could use reflection, but I would at least need what form class I
was in (from within the component) before I could use that.

Still praying for a solution from someone here in the .net community...

JackRazz


| Isn't it just Me.Parent? Or Me.ParentForm?
|
| hth
| Richard
 
R

Richard

Yeah your right. Dumb answer the moment i saw form i thought control.
And theres not alot to hold onto in that IContainer interface
either...

Couldn't you use reflection to get the object that contains the
IContainer interface that passed to the component in its constructor.

And then use reflection again to get the form that is the object so to
speak??

Although this all sounds like an extreme hack. Im sure that getservice
method comes into play somehow but i think you would need control over
the every form/object your component was placed in, because thats
where it needs to be implemented?

Either way im as interested as you are now. Chances are it'll be dead
simple and we'll both look like a couple of dicks, but thats ok cause
i am a dick, and so long as i'm learning something im all for looking
stupid. The great thing is lessons like this you never forget and
we'll probably become experts in component/site interaction now.

Oooooh the fees i'll charge!!

:)

Richard
 
J

JackRazz

Richard,
thanks for the reply, I ended up just passing a reference to me and moved on.

thanks




| Yeah your right. Dumb answer the moment i saw form i thought control.
| And theres not alot to hold onto in that IContainer interface
| either...
|
| Couldn't you use reflection to get the object that contains the
| IContainer interface that passed to the component in its constructor.
|
| And then use reflection again to get the form that is the object so to
| speak??
|
| Although this all sounds like an extreme hack. Im sure that getservice
| method comes into play somehow but i think you would need control over
| the every form/object your component was placed in, because thats
| where it needs to be implemented?
|
| Either way im as interested as you are now. Chances are it'll be dead
| simple and we'll both look like a couple of dicks, but thats ok cause
| i am a dick, and so long as i'm learning something im all for looking
| stupid. The great thing is lessons like this you never forget and
| we'll probably become experts in component/site interaction now.
|
| Oooooh the fees i'll charge!!
|
| :)
|
| Richard
 
R

Richard

thanks for the reply, I ended up just passing a reference to me and moved on.

Excellent.

I wouldn't mind continuing the thread though, if anyone can post a url
about how to get the container a component is sitting in, if you dont
have control over the container i.e: you can only work from component
to container not container to component.

Is there a standard way? I realise we're talking logical not physical
containment but i cant see anything with respect to properties etc
that could be used?

Looking at the interface, it almost seems intentional as if Microsoft
are implicitly saying - why would you care?

(I care because right now i cant)

TIA

Richard
 
R

Richard

I should really clarify this. I dont want the container as an
IContainer, but as a regular object as per the above example, I want a
reference to the form/object it was in.

TIA

Richard
 
J

JackRazz

To close this thread, below is a FindFormForComponent that works. I've now moved on
to seeing if its possible to have a FindFormForMenuItem procedure. I've Started
another thread for that titled FindFormForMenuItem.

JackRazz


Public Shared Function FindFormForComponent(ByVal component As
System.ComponentModel.Component) As Form
Dim i As Integer
Dim container As System.ComponentModel.IContainer = component.Site.Container
Dim components As System.ComponentModel.ComponentCollection =
component.Site.Container.Components
For i = 0 To components.Count - 1
component = CType(components.Item(i), Component)
Dim parentForm As Form
If TypeOf component Is Form Then
Return CType(component, Form)
End If
Next
End Function






| > thanks for the reply, I ended up just passing a reference to me and moved on.
|
| Excellent.
|
| I wouldn't mind continuing the thread though, if anyone can post a url
| about how to get the container a component is sitting in, if you dont
| have control over the container i.e: you can only work from component
| to container not container to component.
|
| Is there a standard way? I realise we're talking logical not physical
| containment but i cant see anything with respect to properties etc
| that could be used?
|
| Looking at the interface, it almost seems intentional as if Microsoft
| are implicitly saying - why would you care?
|
| (I care because right now i cant)
|
| TIA
|
| Richard
 

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

Top