jtran007
asked on
c# global object
HI,
I create an object from form1, how can I refer it from form2?
Thanks,
JT
I create an object from form1, how can I refer it from form2?
Thanks,
JT
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.
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-
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-
ASKER
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
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
Right after initialization where? As long as it is after the call to InitializeComponent() it should be ok.
See the following: https://www.experts-exchange.com/A_4322.html
ASKER
Hi,
In the maiform, right after initialization.
Regards,
JT
In the maiform, right after initialization.
Regards,
JT
ASKER
Hi,
In fact, after InitializeComponent();
Regards,
JT
In fact, after InitializeComponent();
Regards,
JT
Can you post the code in question?
ASKER
Hi,
In the form:
static void Setup()
{
this.textbox1.Text = "testing"; <--- compiler complains
}
public Initialization()
{
InitializeComponent();
Setup();
}
Regards,
JT
In the form:
static void Setup()
{
this.textbox1.Text = "testing"; <--- compiler complains
}
public Initialization()
{
InitializeComponent();
Setup();
}
Regards,
JT
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HI,
Sorry I click the wrong button.
I want to credit this point to Carl.
Regards,
JT
Sorry I click the wrong button.
I want to credit this point to Carl.
Regards,
JT
ASKER
Thanks,
JT
JT