Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing objects from other forms

Status
Not open for further replies.

MrChopper

Programmer
Aug 11, 2004
20
US
Hi,

I'm working in a child form of my parent form, FormMain. In the main form, I have a button with a caption (or 'text' as I Guess it's called now). In the child form, I want to click on a button, and change the text of the button in the parent form. This is how I'm trying to do it, from the child form:

dim formmain as new formmain()
formmain.button1.text = "some text"

I guess the syntax is correct, but it's not working. Any help is appreciated.
 
Forms are objects under .net. And if you want to access another form's contents (or any other object!) you need a reference to it. Meaning, you need a variable which points to the correct instance of the form.

So, when creating the child form (or shortly thereafter), pass a reference to your main form to it, via a parameter to the constructor, or via a property.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top