How can I pass values from one form to another?

前端 未结 10 2606
野的像风
野的像风 2020-12-02 00:43

Consider the situation where I have two windows forms, say F1 and F2. After using F1, I have now called F2.ShowDialog().

10条回答
  •  醉话见心
    2020-12-02 01:20

    int x=10;
    Form1 f2 = new Form1(x);
    f2.ShowDialog();
    

    This is wrote in the form who will pass the value. To recive this value you must make new constructor in the recieved form

    and that will be like that

    public Form2(int x)
      {
            InitializeComponent();
            this.x = x;
     }
    

    and will be notice in the first form when you create the instance from form2 you have two choice on of them one of them let you to pass value

提交回复
热议问题