Home Ask Login Register

Developers Planet

Your answer is one click away!

Jonathon Powell February 2016

What parameter do I pass for form1?

I wish to update a Label from form1 to form2.

I heard that if I want to access a form from another form, I need to put it in a constructor. So I did. To pass the information from Form1, I put that in the parenthesis.

I am getting the error that there is no corresponding argument. I do not know what parameter is supposed to be passed. What must I put?

 public void updateText(Form1 home)
        home.txtOn.Text = "testing!";

        System.Diagnostics.Debug.WriteLine("button clicked!");

    private void button1_Click(object sender, EventArgs e)


Tinwor February 2016

You need to pass to the constructor the current instance of Form1.
To do that you must add to the second form constructor a Form1 parameter Example:

private Form1 home { get; set; }

public Form2(Form1 form) {
    this.home = form;

And in form when you create form2 you must pass this

Form2 form = new Form2(this);

And if you want change a value inside a control of Form1 you must use Controls collection

Post Status

Asked in February 2016
Viewed 1,553 times
Voted 7
Answered 1 times


Leave an answer

Quote of the day: live life