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

Restore Closed MDI Window

5 Answers 291 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Kenneth
Top achievements
Rank 1
Kenneth asked on 12 Jan 2012, 09:27 PM
I have a RadDock  on my main form.  Within this RadDock I create multiple Forms that are create via the following code according to the MDI section of the RadDock documentation,

         messageGenerationForm = new MessageGenerationForm( this );
         messageGenerationForm.Text = "Message Generation";
         messageGenerationForm.MdiParent = this;
         messageGenerationForm.Show();

I set the CloseAction to be Hidden.

They are created as ToolWindows so they can be undocked from the form.  If they are closed, I want to have a menu item that will allow them to be restored.  How is this to be done?


Ken...

5 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 17 Jan 2012, 02:26 PM
Hi Kenneth,

To support this functionality, you can create a FindWindows method and populate your menu items depending on the the result. The search criteria is based on your concrete type, in your case MessageGenerationForm. To display some ToolWindows or a collection of windows, you can use DisplayWindow / DisplayWindows API of RadDock control. Here is a simple implementation:
private void DisplayAllWindows(ToolWindow[] windows)
{
    foreach (var item in windows)
    {
        this.radDock1.DisplayWindow(item);
    }
 
    //or
    this.radDock1.DisplayWindows(windows);
}
 
private ToolWindow[] FindWindows(Type type)
{
    List<ToolWindow> windows = new List<ToolWindow>();
    foreach (ToolWindow item in this.radDock1.DockWindows)
    {
        if (item.Controls.Count > 0 && item.Controls[0].GetType() == type)
        {
            windows.Add(item);
        }
    }
 
    return windows.ToArray();
}

I hope this helps.

All the best,
Julian Benkov
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

0
Kenneth
Top achievements
Rank 1
answered on 18 Jan 2012, 09:20 PM
This doesn't work for me.  Let me try to provide more details to see if you can duplication my situation.  I have my radDock.MdiChildrenDockType set to ToolWindow.  AutoDetectMdiChildren is set to true.  When I try your example, the list is returning types of HostWindow, not ToolWindow.  I can see the two names below in the radDock.DockWindows.ToolWindows list by their names.  When I inspect them the window that I deleted has its MdiChild property set to null.  It appears that when I Hide the tabbed window, it is closing the Form.  So, even if I display the tab again, the contents are blank.  I'm not sure if I'm doing tings correctly.


      private void MainForm_Shown( object sender, EventArgs e )
      {
         messageGenerationForm = new MessageGenerationForm( this );
         messageGenerationForm.Text = "Message Generation";
         messageGenerationForm.MdiParent = this;
         messageGenerationForm.Show();

         eventCreationForm = new EventCreationForm( this );
         eventCreationForm.Text = "Event Creation";
         eventCreationForm.MdiParent = this;
         eventCreationForm.Show();

         // Set the EventList in the MessageGenerationForm so it has access to the events.
         messageGenerationForm.EventList = EventCreationForm.EventList;

         // This sets the active window to be the Event Creation form at startup.  Not sure why, but the
         // EventCreationForm is always at index = 0 in the ToolWindows array.
         radDock1.ActiveWindow = radDock1.DockWindows.ToolWindows[0];

         // Set the properties for the tabbed windows so they are consistent.
         foreach( DockWindow window in radDock1.DockWindows.ToolWindows ) {
            window.AllowedDockState = AllowedDockState.All;
            window.DefaultFloatingSize = new System.Drawing.Size( 1122, 913 );
            window.CloseAction = DockWindowCloseAction.Hide;
         }
      }
0
Julian Benkov
Telerik team
answered on 23 Jan 2012, 12:53 PM
Hi Kenneth,

In this scenario the auto detected child form is handled like a document window and its Close action disposes it. You can change this behavior by handling the DockWindowAdded event. Consider the sample below: 

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls.UI.Docking;
 
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        private RadDock radDock = new RadDock();
        private RadButton radButton = new RadButton();
        private ToolWindow toolWindow = new ToolWindow("My Tool");
 
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            radDock.Dock = DockStyle.Fill;
            this.Controls.Add(radDock);
 
            this.IsMdiContainer = true;
            this.radDock.AutoDetectMdiChildren = true;
            this.radDock.DockWindowAdded += new DockWindowEventHandler(radDock_DockWindowAdded);
 
            Form form = new Form();
            form.Text = "My Form1";
            form.MdiParent = this;
            form.Show();
 
            form = new Form();
            form.Text = "My Form2";
            form.MdiParent = this;
            form.Show();
 
            form = new Form();
            form.Text = "My Form3";
            form.MdiParent = this;
            form.Show();
             
            this.radDock.DockWindow(toolWindow, DockPosition.Left);
 
            radButton.Text = "Show all windows";
            radButton.Click += new EventHandler(radButton_Click);
            toolWindow.Controls.Add(radButton);
        }
 
        void radDock_DockWindowAdded(object sender, DockWindowEventArgs e)
        {
            if (e.DockWindow.DockState == DockState.TabbedDocument && e.DockWindow is HostWindow)
            {
                Form form = e.DockWindow.Controls[0] as Form;
                ToolWindow toolWindow = new ToolWindow(form.Text);
                toolWindow.Controls.Add(form);
                toolWindow.AllowedDockState = AllowedDockState.TabbedDocument | AllowedDockState.Hidden;
                form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
                form.Dock = DockStyle.Fill;
                this.radDock.AddDocument(toolWindow);
                toolWindow.CloseAction = DockWindowCloseAction.Hide;
                e.DockWindow.CloseAction = DockWindowCloseAction.CloseAndDispose;
                e.DockWindow.Close();
            }
        }
 
        void radButton_Click(object sender, EventArgs e)
        {
            IEnumerable<DockWindow> windows = this.radDock.GetWindows<DockWindow>();
            foreach (var item in windows)
            {
                if (item.DockState == DockState.Hidden && item.Controls.Count > 0 && item.Controls[0] is Form)
                {
                    this.radDock.DisplayWindow(item);
                }
            }
        }
    }
}

Please, feel free to contact us, if you have further questions.

Regards,
Julian Benkov
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

0
Kenneth
Top achievements
Rank 1
answered on 31 Jan 2012, 03:57 PM
Julian,

Thanks, this works exactly as I need.

The only problem is, I don't really understand what you are doing in the radDock_WindowAdded() event handler.  Would you be able to take a few minutes and include comments in the code as to what you are doing and why?

Is this solution generalizable to the case where I have a RadDock with ToolWindows within each MDI form? 

I would like to be able to restore ToolWindows within each form, as well as the form itself.


Ken...
0
Julian Benkov
Telerik team
answered on 03 Feb 2012, 04:13 PM
Hi Kenneth,

In the DockWindowAdded I handle the situation when the new MdiChild window is registered to RadDock control and I get the child form, change its properties and insert it in a new ToolWindow and then dispose the previous parent DockWindow. The operation just changes the behavior from DocumentWindow to ToolWindow and prevents the Form from being disposed. I set the FormBorderStyle to None, because otherwise the form will appear with its titlebar in the new ToolWindow. You can use this scenario like a general solution without any issues.

Another approach is to change properties of the Form as we made in DockWindowAdded, and directly add it in a new ToolWindow. In this situation the AutoDetectMdiChildren and the default MDI Form behavior is not needed.

I hope this information is useful. Let me know if you need further assistance. 

Kind regards,
Julian Benkov
the Telerik team

SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Tags
Dock
Asked by
Kenneth
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Kenneth
Top achievements
Rank 1
Share this question
or