0

I have a Winforms Form and I spawn a Route Calculator in a DataGridView Control. After client inputs, it does the calculation and then updates a textbox on the same form after "Update" is pressed. How can I make it so that the value from this textbox in the spawned Form will transfer to an existing textbox on the spawned (child) form back to the parent and close the spawned form at after doing so.

The code below will spawn the child form:

DeliveryLocationCalculator form = new DeliveryLocationCalculator();
            form.Show();

What should go in the button2_Click (Save) button of the child form to make it transfer the textbox value and also close the child form after clicking

leppie
  • 115,091
  • 17
  • 196
  • 297
Jason
  • 652
  • 8
  • 23
  • see [this](http://stackoverflow.com/questions/17032484/passing-data-between-3-separate-winforms) for how to wire events between different forms – DrewJordan May 26 '15 at 15:59

1 Answers1

2

As I understand
If you want transfer value of calculated result from DeliveryLocationCalculator form to the main form and then close DeliveryLocationCalculator form, then create public property in DeliveryLocationCalculator for saving result,

class DeliveryLocationCalculator 
{
    //...
    public decimal FinalResult { get; set; }
}

And use .ShowDialog() method for open calculator DeliveryLocationCalculator form in the modal mode.
After DeliveryLocationCalculator form will be closed, you can read value of property FinalResult, before form will be disposed

//Code in then main form
using form = new DeliveryLocationCalculator()
{
    form.ShowDialog();
    this.TextBoxOnMainForm.Text = form.FinalResult.ToString();
}

From MSDN about ShowDialog method

Fabio
  • 31,528
  • 4
  • 33
  • 72