views:

476

answers:

2

can we use acess textbox value of one form in another form plz give me any suggestions

+7  A: 

You can make the text box public for that form. To do this, change the access modifier property in the properties of the text box:

alt text

Or you can create a public property that exposes the textbox's value:

public string Foo {
  get { return txtFoo.Text; }
}

The latter is probably preferrable if you only need read-only access to the textbox's text. You can add a setter as well if you also need to write it. Making the complete textbox public allows for much more access than you probably want to have in this instance.

Joey
A: 

Another way is pass the TextBox to the constructor of the other form, like this:

    private TextBox _control;
      public SomeForm(TextBox control)
    {
        InitializeComponent();
        this._control = control;
    }

and use the this._control.text = "bla bla";

jaspion