c# global object

HI,

I create an object from form1, how can I refer it from form2?
Thanks,
JT
jtran007Asked:
Who is Participating?
 
Carl TawnConnect With a Mentor Systems and Integration DeveloperCommented:
It will. The TextBox is an instance member of the Form, you cannot access it from a static method.
0
 
Carl TawnSystems and Integration DeveloperCommented:
Depending on what it is you are trying to achieve, you would probably just be better of passing the object to the second form in its constructor.
0
 
it_saigeDeveloperCommented:
As long as the object is declared publically you could use:

form1.objectname in form2.

This is not in anyway the recommended way of accomplishing this.  Carls suggestion is more accurate from a programming standpoint.

-saige-
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
jtran007Author Commented:
Hi,

Thanks for your suggestion. Also I have a minor to ask. In the form1, I have define  
a textbox, right after the Initialization, I try copy the content of object to textbox.txt but
the compiler complains that textbox is not defined. I don't understand. Please help.
Thanks,
JT
0
 
Carl TawnSystems and Integration DeveloperCommented:
Right after initialization where? As long as it is after the call to InitializeComponent() it should be ok.
0
 
käµfm³d 👽Commented:
0
 
jtran007Author Commented:
Hi,

In the maiform, right after initialization.

Regards,
JT
0
 
jtran007Author Commented:
Hi,

In fact, after InitializeComponent();

Regards,
JT
0
 
Carl TawnSystems and Integration DeveloperCommented:
Can you post the code in question?
0
 
jtran007Author Commented:
Hi,

In the form:

 static void Setup()
{
   this.textbox1.Text = "testing";   <--- compiler complains
}
 public Initialization()
        {
            InitializeComponent();

            Setup();
         }


Regards,
JT
0
 
jtran007Author Commented:
HI,
Sorry I click the wrong button.
I want to credit this point to Carl.

Regards,
JT
0
 
jtran007Author Commented:
Thanks,
JT
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.