Click here to Skip to main content
15,884,794 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Pass values between 2 MDI Child Forms using C# split container
Posted
Updated 17-Jan-21 3:03am

The best method is to go via the MDI parent.

Create an event in the source child which says "I have data"
The Parent handles the event and either gets the data from the EventArgs, or via a child property.
It then passes the data to the other child via a property.

This way, neither form need to know about the existence of the other, only the form which supports both forms needs to do that, and it decides what to do with the data.
 
Share this answer
 
You can store the value in public static variable. Example:
C#
public class MyGlobalValue
{
    public static string MyGlobalString = "Hello";
    public static int MyGlobalInt = 1234;
}

You can access it anywhere in your application like this:
C#
MyGlobalValue.MyGlobalString += ", nice to meet you.";
MesssageBox.Show(MyGlobalValue.MyGlobalString);

C#
int a = MyGlobalValue.MyGlobalInt + 1;
MessageBox.Show("MyGlobalValue.MyGlobalInt + 1 = " + a);
 
Share this answer
 
Comments
DaveyM69 4-Nov-12 16:00pm    
This is rarely a good solution, Griff's solution is the correct way to do this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900