0

I have a label on Form1 called oldNumber. When I click a button which loads Form2, a label called newNumber, will be displayed when form2 loads.

My presumption is for the label to display the number from the previous form as the form loads it must be placed within the Form2's load method. Although I'm not entirely sure how to call the oldNumber in Form1 to display in the newNumber Label on form2.

There is similar questions asked to this, but none have managed to help me.

Thanks!

P.s Im new to .NET, and winForms. So question is quite simple i know.

Sameer
  • 2,143
  • 1
  • 16
  • 22

2 Answers2

1

Modify your form2 constructor to receive a string

public class Form2:Form
{

    public void Form2(string textFromForm1)
    {
        InitializeComponent();
        this.labelOnForm2.Text = textFromForm1;
    }
    ....
}

then when you call the Form2 Show/ShowDialog in Form1 instance

Form2 frm = new Form2(this.labelOnForm1.Text);
frm.Show();
Steve
  • 213,761
  • 22
  • 232
  • 286
-1

This link might help you as there are many similar principles that can be done working with multiple forms that may rely on each other. It has a few links, even a full sample showing how to work multiple forms / methods / properties, etc

Community
  • 1
  • 1
DRapp
  • 47,638
  • 12
  • 72
  • 142
  • References to references of references seems like a bad way to answer questions. If you're going to recycle answers, at least take time to repost the code. – DonBoitnott Jan 30 '14 at 18:16
  • @DonBoitnott, So noted, but so many questions about how to on formA/formB. Also, with different options and approaches to giving them a solution was why I pointed to that specific link. – DRapp Jan 30 '14 at 19:47
  • Then the appropriate course would be to flag as duplicate and vote to close. – DonBoitnott Jan 30 '14 at 19:48