Using other class controls

G

Guest

After trying to solve thois bymyself i gave up. I was i visual basic 6
programmer, now i m getting to java and c#. The problem i have is simple, but
it seems to be a hell for me.

<EXPLANATION>

I' ve 2 forms, Form1 is one class and Form2 is another class. On form1 i've
a textbox (textBox1), and on form2 i've a button(button1). What i am trying
to do is when i press the button on form2 i want to change the value of the
textBox1 placed on form1.

<CODE>

On Form1 a do the following:

Form2 v_Form = new Form2();
v_Form.Show.

with that a create a new instance of Form2 and i show it then.
On Form2 i did the following:

private void button1_click(.....)
{
Form1.ControlCollection["textBox1"].text="Marco";
}


</CODE>

</EXPLANATION>

I've tryied many otrher ways, to remenber that i set the control (textBox1)
public in Form1.
Can you please help me on this.
Thank you
Me_Titus
 
G

Guest

But how do i do that, i've tryied everything i knew, could you show me the
light.
Thanks,
Me_Titus


mortb said:
You need to set a reference to form1 on form2 to be able to access it

cheers,
mortb

Me_Titus said:
After trying to solve thois bymyself i gave up. I was i visual basic 6
programmer, now i m getting to java and c#. The problem i have is simple,
but
it seems to be a hell for me.

<EXPLANATION>

I' ve 2 forms, Form1 is one class and Form2 is another class. On form1
i've
a textbox (textBox1), and on form2 i've a button(button1). What i am
trying
to do is when i press the button on form2 i want to change the value of
the
textBox1 placed on form1.

<CODE>

On Form1 a do the following:

Form2 v_Form = new Form2();
v_Form.Show.

with that a create a new instance of Form2 and i show it then.
On Form2 i did the following:

private void button1_click(.....)
{
Form1.ControlCollection["textBox1"].text="Marco";
}


</CODE>

</EXPLANATION>

I've tryied many otrher ways, to remenber that i set the control
(textBox1)
public in Form1.
Can you please help me on this.
Thank you
Me_Titus
 
N

Nick Malik

Hope this helps,

public class Form2 : <inheritied stuff>
{
public Textbox refTxt1; // <-- add this line

..... all your other code ...

private void button1_click(.....)
{
refTxt1.text="Marco";
}
}

public class Form1: <inherited stuff>
{
private void MyMethod()
{
Form2 v_Form = new Form2();
v_Form.refTxt1 = Text1; // <-- add the reference to the text
box into form2's class
v_Form.Show.
}
}


--- Nick

Me_Titus said:
But how do i do that, i've tryied everything i knew, could you show me the
light.
Thanks,
Me_Titus


mortb said:
You need to set a reference to form1 on form2 to be able to access it

cheers,
mortb

Me_Titus said:
After trying to solve thois bymyself i gave up. I was i visual basic 6
programmer, now i m getting to java and c#. The problem i have is simple,
but
it seems to be a hell for me.

<EXPLANATION>

I' ve 2 forms, Form1 is one class and Form2 is another class. On form1
i've
a textbox (textBox1), and on form2 i've a button(button1). What i am
trying
to do is when i press the button on form2 i want to change the value of
the
textBox1 placed on form1.

<CODE>

On Form1 a do the following:

Form2 v_Form = new Form2();
v_Form.Show.

with that a create a new instance of Form2 and i show it then.
On Form2 i did the following:

private void button1_click(.....)
{
Form1.ControlCollection["textBox1"].text="Marco";
}


</CODE>

</EXPLANATION>

I've tryied many otrher ways, to remenber that i set the control
(textBox1)
public in Form1.
Can you please help me on this.
Thank you
Me_Titus
 

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