MLyons10

I am able to populate a textBox in the same form with text from another textBox, but I would like to when I open Form2 for text from one of the textBoxes in Form1 to automatically populate a textBox in Form2. Is this possible How would I do this Here is the code that I tried to use:

Form1

private void button2_Click(object sender, EventArgs e)
{
Photos form = new Photos(WindowsApplication1.Form1.textBox1.Text);
form.Show();
}

Form2

public Photos(String Name)
{
InitializeComponent();
textBox19.Text = Name;
}


What am I doing wrong I don't understand why this won't work... Any help and information is greatly appreciated.

Thanks,



Re: Visual C# Express Edition How do I populate a textBox in a form with text from a different form?

Hayder Marzouk

Hi,

You have a little mistake in your code at this line :

Photos form = new Photos(WindowsApplication1.Form1.textBox1.Text);

To get the text of your textbox u have to get it from the instance of the container form. In other words calling WindowsApplication1.Form1.textbox1.text works only if the textbox is a static member if the form.

So, u have just to write :

Photos form = new Photos(this.textBox1.Text);

Another idea is to change the modifier of the textbox19 to internal or public (using the visual studio properties editor) and use the following code :

Photos form = new Photos();

form.textbox19.Text = this.textbox1.Text;

HTH.

Hayder Marzouk






Re: Visual C# Express Edition How do I populate a textBox in a form with text from a different form?

h1dden

Form 1

Code Snippet

private void button2_Click(object sender, EventArgs e) {
Form2 frm = new Form2();
frm.Show();

}
public TextBox TextBox1 {
get {
return textBox1;
}
}

Form 2
Code Snippet

private Form1 otherForm = new Form1();
private void Form2_Load(object sender, EventArgs e) {
textBox19.Text = otherForm.TextBox1.Text;
}






Re: Visual C# Express Edition How do I populate a textBox in a form with text from a different form?

MLyons10

Thank you both for your help, I greatly appreciate it. I could not for the life of me figure out what the problem was. It's amazing how in C# there is always several ways to accomplish the same goal. It is very interesting to me.

Thanks Again,





Re: Visual C# Express Edition How do I populate a textBox in a form with text from a different form?

bassamimam

hey hi i have a small q in the topic

i am using VWD C# i want to like add text in the frist textbox and when i click submit in an anther form the other text box text changes to what i have written in the first text box