Export (0) Print
Expand All
Expand Minimize

Code: Getting a Value from Another Form (Visual C#)

Visual Studio .NET 2003

This example retrieves a value from a text box on a Windows Form and displays it in a text box on another form.

Example

In Form1.cs:

private Form2 otherForm;
private void GetOtherFormTextBox()
{
    textBox1.Text = otherForm.TextBox1.Text;
}

In Form2.cs:

public TextBox TextBox1
{
    get
    {
        return textBox1;
    }
}

Compiling the Code

This example requires:

  • Two forms named Form1 and Form2, each containing a TextBox control named textBox1. Form1 should create an instance of Form2 and assign it to otherForm; GetOtherFormTextBox will copy the text in Form2's textBox1 to Form1's textBox1.

See Also

Windows Forms Example Topics | Displaying One Form from Another

Show:
© 2014 Microsoft