Linking objects between forms

  • Thread starter Thread starter jed
  • Start date Start date
J

jed

How can i get access to textbox or an object in another form.I need
to insert a value from a textbox on form1 into a textbox on form2 but
cant get the textbox to appear in intellisense.I am a beginner still
learning C# thanks.
 
How can i get access to textbox or an object in another form.I need
to insert a value from a textbox on form1 into a textbox on form2 but
cant get the textbox to appear in intellisense.I am a beginner still
learning C# thanks.

you can pass the values in the constructor of form2
 
DarkSoul said:
you can pass the values in the constructor of form2
to add to DarkSoul's reply you need to either pass form1 or the object
you wish to talk to in as a parameter to form2 or populate an existing
value in form2


public class Form1
{
public string objectname = "";

public somemethod()
{
// Create form2 here and pass a reference to Form1 to // the
constructor of form2

Form2 frm = new Form2(this);

// or populate a property of Form2 like this

frm.somepropertyname = this; // you could also populate
this property with whatever object you wish
frm.Show();
}
}

public class Form2
{
public Form thecallingform;

public Form2(Form frm)
{
this.thecallingform = frm;
}

public void anothermethod()
{
this.thecallingform.objectname = "foo";
}
}

hope this helps
 
Do you have to write all that just to take text from a textbox on
windowsform1 to another textbox on windowsform2.I have a button on
form1 when the user clicks the button i want to transfer the text.
 

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

Back
Top