使用C#拆分容器在2个MDI子窗体之间传递值 [英] Pass values between 2 MDI Child Forms using C# split container

查看:71
本文介绍了使用C#拆分容器在2个MDI子窗体之间传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#拆分容器在2个MDI子窗体之间传递值

How to Pass values between 2 MDI Child Forms using C# split container

推荐答案

最好的方法是通过MDI父级.

在来源子项中创建一个事件,内容为我有数据"
父级处理事件,并从EventArgs或通过子级属性获取数据.
然后,它通过属性将数据传递给另一个子级.

这样,任何一种形式都不需要知道另一种形式的存在,只有支持两种形式的形式都需要这样做,并且它决定如何处理数据.
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.


您可以将值存储在公共静态变量中.示例:
You can store the value in public static variable. Example:
public class MyGlobalValue
{
    public static string MyGlobalString = "Hello";
    public static int MyGlobalInt = 1234;
}


您可以像这样在应用程序中的任何位置访问它:


You can access it anywhere in your application like this:

MyGlobalValue.MyGlobalString += ", nice to meet you.";
MesssageBox.Show(MyGlobalValue.MyGlobalString);


int a = MyGlobalValue.MyGlobalInt + 1;
MessageBox.Show("MyGlobalValue.MyGlobalInt + 1 = " + a);


这篇关于使用C#拆分容器在2个MDI子窗体之间传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆