开发者

MDIContainer Pass variable and One window

i

Hallo,

m using开发者_StackOverflow社区 MDIContainer.

1. How can i pass the varaible from parent to child ?

2.How can i prohibited to open more than 1 window with the same Name (That means in my MenuStrip there are Ordre,Tarif,Config... when user already open the Ordre, when he click the menustrip ordre again, it not open a new window/created a new child but pointed to the ordre window that already open) ?

Thanx before.


Create a private, protected or public member in your mdicontainer window:

class MyMdiContainer : Form
{
    private object m_var;

    // Property approach
    public object MyVar
    {
        get { return m_var; }
        set { m_var = value; }
    }
}

And here is the mdi child:

class MyMdiChild : Form
{
    private object m_childVar;

    void Communicate()
    {
        // Read variable
        this.m_childVar = ((MyMdiContainer) this.MDIParent).MyVar;

        ((MyMdiContainer) this.MDIParent).MyVar = "Child Foo";
    }
}

In the example above we use two fields, each one for the two classes, property for storing the var in the MDI parent, and method in child for making a communication on the variable and storing a copy inside the child.

This is useful for parent to child, but it should be implemented in different way for parent to many children with synchronization.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜