Search code examples
c#parentmdi

Name of MDI Parent


I don't know if I've made this messy or not......

I have an MDI parent created thus:

namespace APRSTW
    {
    static class Program
        {
        [STAThread]
        static void Main()
            {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainAPRSTW()); //<= key call
            }
        }
    }

In MainAPRSTW.cs, you find this....

namespace APRSTW
    {
    public partial class MainAPRSTW : Form
        {......lots of stuff here, and the MDI parent happens here.......}

Now we have the parent MDI form. Next is the class that starts the process of creating the child form.

namespace TeleDecoder
    {
    class TDecoder
        {......}

A new instance of TDecoder also creates a new instance of the following form

namespace ChildNode
    {
    public partial class Node : Form
        {......}

with the code

      ChildNodeForm = new Node();
      ChildNodeForm.MdiParent = ?????????;

The question is, what do I use for "?????????" ?

Or, do I need to make some name changes?

I hope I got this across well.

Chuck


Solution

  • When you do this:

    Application.Run(new MainAPRSTW());
    

    you need to store a reference to that form:

    public static Form mainForm;//at top of module
    mainForm = new MainAPRSTW();
    Application.Run(mainForm);
    

    and then you can do

    ChildNodeForm.MdiParent = mainForm;