How to Pass values to another Form
Ok. Lets say you have 2 Forms. Form1 and Form2.
In Visual Basic 6 this is simple codes with 1 line only: Form2.text1.text = Form1.text1.text
Thats so Simple.
But in C# not 1 line code. I have 2 ways to get a text from Form1/Form2.
FIRST WAY:
1.) Goto Form1 then Double Click it. At the code type this.
public string CaptionText
{get {return textBox1.Text;}
set { textBox1.Text = value; }}
note: the value of your textbox1.text = sayre;
2.) Goto Form2 then Double click it. At the code type this.
// At your command button In Form2
// At your command button In Form2
private void button1_Click(object sender, EventArgs e)
{
Form1 sForm1 = new Form1();
textBox1.Text = sForm1.CaptionText;
}
SECOND WAY:
1.) Goto Form2 then Double click it. At the code type this.
public Form2(string sTEXT)
{
InitializeComponent();
textBox1.Text = sTEXT;
}
2.) Goto Form1 then Double click it. At the code type this.
//At your command button in Form1
private void button1_Click(object sender, EventArgs e)
{
Form2 sForm = new Form2(textBox1.Text);
sForm.Show();
}
0 comment:
إرسال تعليق