-1

I have an Order_Form with a button that takes you to Client_form to choose there a client name. I wanted to pass the client name back to the Order_Form (by clicking a button) but without using

Order_Form  frm1 = New Order_Form();

cause I will be lost all the data in the Order_Form. How can I do that?

Sender
  • 6,660
  • 12
  • 47
  • 66

1 Answers1

3

You just need to pass the instance of the Order_Form to your Client_Form:

public class Order_Form : Form
{
    public Order_Form()
    {
        // ...
    }

    public string clientName = String.Empty;

    public void GetClientName()
    {
        // Pass the instance of the Order_Form
        Client_form cform = new Client_form(this);
        cform.Show();
    }
}

public class Client_form
{
    public Client_form(Order_Form instance)
    {
        // Use the passed instance to access your clientName
        instance.clientName = "your string back";
    }
}
C4d
  • 3,183
  • 4
  • 29
  • 50