Matan Maimon

Matan Maimon

  • NA
  • 1
  • 10.6k

help|Win FORMS - read text from "textBox" that just created

Nov 7 2010 10:33 AM
First, here's my code:
                TextBox  textBox1 = new TextBox();
textBox1.Name = "textBox1";
textBox1.Text = "hellow";

as you see I create here a new "textBox" that call "textBox1".
Now, if I want to read his text (textBox1.Text), how can I do that?

I of course talk about how can I do that from another function but in the same FORM, for example:
    private void newBox()
{
TextBox textBox1 = new TextBox();
textBox1.Name = "textBox1";
textBox1.Text = "hellow";
}

private void readText()
{
newBox();
MessageBox.Show(textBox1.Text);
}

This code above will give me an Error!

Although that he create the "textBox1" before he try display it on "MessageBox" he cant read him, and will think that he even not existent.

I explain myself best that I can, I know that have some problem with my english, but still I expect to get some answers,
thank a lot.



Answers (2)