reference a variable in form1 from form2 in C#?

  • Thread starter Thread starter Brian Underhill via DotNetMonster.com
  • Start date Start date
B

Brian Underhill via DotNetMonster.com

I have a textbox in form2 that i need to use in form1. How do I get acces to
it? I am having trouble finding an example on this...probably due to
inexperience



thanks
brian
 
Declare the textbox as public in Form2. Or wrap the textbox property that
you want to access acorss the form as public. For example, to wrap the Text
property of the textbox as a property of Form2, have this in Form2:

public string TextBoxText
{
get {return TextBox1.Text;}
set {TextBox1.Text = value;}
}

Then from Form1,

Form2 x = new Form2();
x.TextBoxText = "My Text";

HTH.


I have a textbox in form2 that i need to use in form1. How do I get acces
to
it? I am having trouble finding an example on this...probably due to
inexperience



thanks
brian
 

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