Intekhab Khan
Intekhab Khan

Reputation: 1863

Passing values between form-With constructor-Error comes!-C#-Winforms

When i am passing values from the one form(Form1) to other form(Form2) Via constructor and when i click button to pass value error comes NULLRefrence error was unhadled! Please tell me what do.i search on internet same codes comes ,but the error comes.

Form2 Constructor

public Form2(string ab)
    {

        textBox1.Text = ab;


        InitializeComponent();
    }

Form1 ,On button click event

private void button1_Click(object sender, EventArgs e)
    {

        Form2 obj = new Form2(textBox1.Text);
        obj.ShowDialog();
        this.Hide();
    }

Upvotes: 0

Views: 1267

Answers (1)

SLaks
SLaks

Reputation: 887453

textBox1 is only created by InitializeComponent.

Before you call InitializeComponent, it's null.

Upvotes: 4

Related Questions