Using ref with 2 shapes ..?

advertisements

I have 2 forms..

from first form i call 2nd form... in second form i do some calculations and i want to get the result in first form after closing second form.

First Form Code

public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm
{
    String s = "";
    public XtraForm1()
    {
        InitializeComponent();
    }

    private void simpleButton1_Click(object sender, EventArgs e)
    {
        s = textEdit1.Text;
        XtraForm2 x = new XtraForm2(ref s);

        x.ShowDialog();
        MessageBox.Show(s); // Here I want to get the data from 2nd form.
    }
}

2nd Form Code

public partial class XtraForm2 : DevExpress.XtraEditors.XtraForm
{
    string s2 = "";
    public XtraForm2(ref string s1)
    {
        InitializeComponent();
        s2 = "hai";
        s1 = s2;
    }

    private void simpleButton1_Click(object sender, EventArgs e)
    {
        // here i do some operations and i want to store it in variable s1 so that i will get the result in 1st form.
        this.Close();
    }
}


There is a number of things you could do.

But easiest is to create a property on your second form, put the result in there and call it from your first form after the ShowDialog() like MessageBox.Show(x.MyProperty);