MdiChildren

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BbEsy
    New Member
    • Sep 2009
    • 28

    MdiChildren

    hello Im working on MDI form application.

    I have one problem i need to know when the mdi child cclosing, and need to know him name or .text.

    how i can do this. How I can get it ?

    Or how I can use MdiChildActivat e event to get it.

    thx
  • edurazee
    New Member
    • Dec 2009
    • 13

    #2
    Although not 100%, this code may help you.

    Code:
    public partial class MDIForm : Form
        {
            public string Message
            {
                get { return this.textBox1.Text; }
                set { this.textBox1.Text = value; }
            }
    
            public MDIForm()
            {
                InitializeComponent();
            }
    
            int cout = 0;
            private void btnCreateChild_Click(object sender, EventArgs e)
            {
                ChildForm f = new ChildForm(cout.ToString());
                f.MdiParent = this;
                f.Show();
                ++cout;
            }
        }
    public partial class ChildForm : Form
        {
            public ChildForm(string name)
            {
                InitializeComponent();
                this.Text = name;
            }
    
            private void ChildForm_FormClosing(object sender, FormClosingEventArgs e)
            {
                MDIForm f = this.ParentForm as MDIForm;
    
                if (f != null)
                {
                    f.Message = "Child " + this.Text + " is just closed";
                }
            }
        }
    
    static class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MDIForm());
            }
        }
    Here is the picture:

    Comment

    • BbEsy
      New Member
      • Sep 2009
      • 28

      #3
      Thx, I solve this yesterday.

      I solve it another way.

      Code:
      public void MDI_Child_closing(string strID)
      {
      any action
      }
      
      private void TestChild_FormClosing(object sender, FormClosingEventArgs e)
      {
      ((Form1)this.MdiParent).MDI_Child_closing(this.Text);
      }

      Comment

      Working...