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
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).
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;
}
}
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);
}
}
}
}
}
Regards,
Julian Benkov
the Telerik team
SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).
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...
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.
Julian Benkov
the Telerik team
SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).