Trying to emulate what the designer generated code does has brought me no joy. I have created a static method to check if a container exists before opening a dockable window. This works great, but for some reason the docked window does not draw until I resize the form that it's docked in.
Can someone take a look at this and tell me what's wrong? I am using .Net 3.5, so I've made this an "extension method". To try it in .Net 2.0, just remove the word "this" in the parameter definitions of OpenDockedEx.
static class DockHelper
{
public static void OpenDockedEx(this UserDockableWindow window,
ContainerDockLocation location, WindowOpenMethod openMethod)
{
// Get the dockable window's docking manager.
SandDockManager manager = window.Manager;
// Try to find an existing container to dock into.
DockContainer container = manager.FindDockContainer(ContainerDockLocation.Bottom);
if( container != null )
{
// Found one, just call OpenDocked.
window.OpenDocked(location, openMethod);
return;
}
// An existing container was not found, create one now.
// Get the docking manager's container form.
Form form = manager.DockSystemContainer as Form;
form.SuspendLayout();
// Create a new dock container.
container = new TD.SandDock.DockContainer();
container.SuspendLayout();
// Setup the dock container...
// TODO: This is hard-coded, copied from the designer generator for now...
container.ContentSize = 200;
container.Controls.Add(window);
container.Dock = System.Windows.Forms.DockStyle.Bottom;
container.LayoutSystem = new TD.SandDock.SplitLayoutSystem(new System.Drawing.SizeF(250F, 400F), System.Windows.Forms.Orientation.Vertical, new TD.SandDock.LayoutSystemBase[] {
((TD.SandDock.LayoutSystemBase)(new TD.SandDock.ControlLayoutSystem(new System.Drawing.SizeF(250F, 400F), new TD.SandDock.DockControl[] {
((TD.SandDock.DockControl)(window))}, window)))});
container.Location = new System.Drawing.Point(0, 346);
container.Manager = manager;
container.Name = "dockContainer1";
container.Size = new System.Drawing.Size(792, 204);
container.TabIndex = 4;
// Add the new docking container to the form.
form.Controls.Add(container);
container.ResumeLayout(false);
form.ResumeLayout(false);
// Finally, open the window.
window.OpenDocked(location, openMethod);
// NO JOY - window does not draw until the form is resized.
// I have tried calling form.Refresh(); however this causes SandDock to have a NullReferenceException.
}
}
ARG!!