How can I pass values from one form to another?

前端 未结 10 2604
野的像风
野的像风 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:28

    May be I am late. but all those who may want.

    In destination form have a constructor defined like this

    public partial class Destination: Form
    {
        string valueAccepted;
        public Destination(string _valuePassed)
        {
            InitializeComponent();
            this.valueAccepted= _valuePassed;
        }
    }
    

    and in Source Form call the form like this

            Source sourceForm= new Source ("value Passed");
            sourceForm.ShowDialog();
    

    this way "value Passed" is passed from Form Source to Form Destination

提交回复
热议问题