Closing an MDI Child Form

4 posts, 0 answers
  1. Fabrizio
    Fabrizio avatar
    20 posts
    Member since:
    May 2019

    Posted 17 May 2019 Link to this post

    Hello,

    I create a RadForm (named mainForm) with a RadDock.

    I set the mainForm.MdiContainer = true and the radDock1.AutoDetectMdiChildren = true  and the chilForm.MdiParentwith = mainForm (for all children form).

    When I close my mainForm, in the FormClosing event I call radDock1.CloseAllWindows() and FormClosing event of MDI children form fires.

     

    However can you tell me if is it possible to show (to active) every child form when FormClosing is called ?

     

    Thank you

    Bests regards

     

  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3993 posts

    Posted 17 May 2019 Link to this post

    Hello, Fabrizio,     

    The FormClosing event is supposed to be fired when a certain form is about to be closed. According to the provided information it is difficult for me to understand completely what is the exact requirement that you are trying to achieve. 

    In order to activate a certain form, you can use the RadDock.ActivateWindow method passing the HostWindow of the respective form. Note that the activating and closing of the form will be executed very fast. That is why you may block the UI thread. Please refer to the following code snippet which result is illustrated in the attached gif file:

    public MainForm()
    {
        InitializeComponent();
     
        this.IsMdiContainer = true;
        this.radDock1.AutoDetectMdiChildren = true;
        this.FormClosing += MainForm_FormClosing;
     
        for (int i = 0; i < 5; i++)
        {
            RadForm childForm = new RadForm();
            childForm.Text = "MDI Child " + DateTime.Now.ToShortTimeString();
            childForm.MdiParent = this;
            childForm.Show();
        }
    }
     
    private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        while (this.radDock1.DockWindows.Count != 0)
        {
            this.radDock1.ActivateWindow(this.radDock1.DockWindows.First());
            Thread.Sleep(1500);
            Application.DoEvents();
            this.radDock1.DockWindows.First().Close();
        }
    }

    However, if it is not the case, it would be greatly appreciated if you specify in details what is the exact goal that you are trying achieve. Thus, we would be able to think about a suitable solution and assist you further. Thank you in advance.

    I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Fabrizio
    Fabrizio avatar
    20 posts
    Member since:
    May 2019

    Posted 17 May 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hello,
    Thank you.
    In fact the goal is that I have several MDI children form, when I close the application, I must to close each MDI child and ask a confirmation RadMessageBox for each.

    So when the closing confirmation message is showed, I have to display the mdi form concerned.

    Best regards
    Fabrizio
  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3993 posts

    Posted 20 May 2019 Link to this post

    Hello, Fabrizio,     

    You can find below a sample code snippet demonstrating how to show a confirmation button, activate the document before closing the main MDI parent:

    public MainForm()
    {
        InitializeComponent();
     
        this.IsMdiContainer = true;
        this.radDock1.AutoDetectMdiChildren = true;
        this.FormClosing += MainForm_FormClosing;
     
        for (int i = 0; i < 5; i++)
        {
            RadForm childForm = new RadForm();
            childForm.Text = "MDI Child " + i;
            childForm.MdiParent = this;
            childForm.Show();
        }
    }
     
    private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
    {
        while (this.radDock1.DockWindows.Count != 0)
        {
            this.radDock1.ActivateWindow(this.radDock1.DockWindows.First());
            if (RadMessageBox.Show("Are you sure?", this.radDock1.ActiveWindow.Text, MessageBoxButtons.OK) == System.Windows.Forms.DialogResult.OK)
            {
                this.radDock1.DockWindows.First().Close();
            }
        }
    }

    Should you have further questions please let me know.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top