get reference of the containing form

  • Thread starter Thread starter Neo
  • Start date Start date
N

Neo

I am trying to create a custom control, & in this control i need to access
the form where this control is added.
How can i do this.

- I tried to accept a new parameter in the constructor of this new control,
but then i can't drop the control onto the form.
- I don't want to drop the control onto the form & set the reference to the
form in a property of the control from code, because if i want to drop this
control 10 times in 10 forms, then this means that i will always have to set
the reference of the form in a property of this control.

I just want to access the form from my control & do not want to put ANY code
in the form (but only have to be able to drop this control on the form and
this will be enough)

How can i resolve my problem.
 
Neo,

Do you mean that you want to set in your control method

Sub new
messagebox.show(me.parent.tostring) 'A stupid piece of code however just to
show how.
end sub

I hope this helps?

Cor
 
aaaaaggggh, silly me. never thought of looking for a property PARENT.
Excellent chum, thank you.
You have saved a lot of my development time.... I have been trying to rack
my brain on this.
looking for a simple solution but thinking too darn hard.

Thank you again.
 
For some odd reason i never got the PARENT or the PARENTFORM to work,
but found that the FindForm() method is what i need.
I think this is the ideal way of getting the form on which this control is -
cuz thats what the method says it does.
 
Cor,
That can be when you use a webform
Huh?

Control.FindForm is a Windows Forms Control method & is used to find the
Form the control is on. For details see:

http://msdn.microsoft.com/library/d...stemwindowsformscontrolclassfindformtopic.asp

http://msdn.microsoft.com/library/d...systemwindowsformscontrolclassparenttopic.asp


Are you perhaps think of Web Form's Control.FindControl?

http://msdn.microsoft.com/library/d...rfsystemwebuicontrolclassfindcontroltopic.asp

Hope this helps
Jay
 
Jay,

You are right. I was answering this impulsive.

Because that I use and was thinking about that.

Cor
 
The last sentence is cryptic
Because that I use and was thinking about that.
Because that ( Me.FindControl("Form1")) I know the use for and I was
thinking about that.

Cor
 

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