This is a migrated thread and some comments may be shown as answers.

Closing an MDI Child Form

3 Answers 1388 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Fabrizio
Top achievements
Rank 1
Fabrizio asked on 17 May 2019, 10:03 AM

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

 

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 May 2019, 01:03 PM
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.
0
Fabrizio
Top achievements
Rank 1
answered on 17 May 2019, 04:07 PM
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
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 May 2019, 11:39 AM
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.
Tags
Dock
Asked by
Fabrizio
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Fabrizio
Top achievements
Rank 1
Share this question
or