Help me to getting value in another form (C#)
I have 2 form: form1; form2
in form 1: textBox1 and Button1
code Button1_Click(){
form2 f = new form2();
f.show()}
help me to get value in textBox1 (form1) at form2
I have 2 form: form1; form2
in form 1: textBox1 and Button1
code Button1_Click(){
form2 f = new form2();
f.show()}
help me to get value in textBox1 (form1) at form2
I have 2 form: form1; form2
in form 1: textBox1 and Button1
code Button1_Click(){
form2 f = new form2();
f.show()}
help me to get value in textBox1 (form1) at form2
thanks!
Hi ctlatd2,
C# is an object oriented language, evry form is a class.
You Need To this :
1. In form2 you need to writh a PUBLIC function that return a value.
2. In the new form "f" you need to call the function like this :
a. ((FrmMain)this.MdiParent).fnGetValue(); // if it's mdi form
b. Form2 f= new Form2() ;
f.fnGetValue() // in your case
Best Regards,
Boaz Shalev.
public string getStringValue() {
return myText.Text;
}
in your button click:
Button1_Click(){
form2 f = new form2();
f.Owner = this;
f.show()
}
in your Form2:
Form2() {
InitializeComponents();
Text1.Text = ((Form1) this.Owner).getStringValue();
}
It's only a pseudo code, so I hope that you got what im trying to explain...
cheers,
Paul June A. Domag
private void button1_Click()
{
Form2 f = new Form2(textBox1);
f.Show();
}
Or simply change the modifier of your textBox1 from private (default) to internal; so your Form1's textBox1 will be visible for all the Forms within your project.
Example:
private void button1_Click() ((Form1)Tag).textBox1 To get the TextBox from Form1.
{
Form2 f = new Form2(textBox1);
f.Tag = this;
f.Show();
}On your Form2, you can simply make a call:
-chris
Button1_Click(){ public that ok!
form2 f = new form2();
f.frm = this;
f.show();
}
in form2:
Form2_Show(){
MessageBox.Show(frm.getStringValue());
}