Divelements Community
Customer discussion of all Divelements products

Showing UserDockableWindows at runtime is a pain (SandDock 3.0.1.1)

Latest post 01-07-2008 9:41 by WayneB. 6 replies.
  • 01-07-2008 4:34

    • WayneB
    • Top 150 Contributor
    • Joined on 09-06-2007
    • Posts 9

    Crying [:'(] Showing UserDockableWindows at runtime is a pain (SandDock 3.0.1.1)

    Thank you for SandDock, it's the best performing docking solution that I've found. However, I have a small problem: Displaying a UserDockableWindow at runtime is a pain! There was only one demo that came with this product and it only shows you how to setup your docking windows at design time.

    I do not want to create any dockable windows at design time because I don't need them all yet and furthermore, I don't want to go into my MainWindow and set the default properties of a dockable window in that designer, I just want it to use the default settings that I apply in my UserDockableWindow's designer.

    So, I tried displaying my UserDockableWindow at runtime like this.

    // ActivityDetailsTool's constructor does this.Manager = dockMgr...
    ActivityDetailsTool tool = new ActivityDetailsTool(mainWindow.DockMgr);
    tool.OpenDocked(ContainerDockLocation.Bottom);

    I use this technique to open my UserTabbedDocuments (except I just call Open) and it works. It doesn't work here because there is no DockContainer or LayoutSystem created yet to hold this dockable window, because I didn't add any at design time. So, why doesn't the tool just tell it's manager to create one then? In your own post you stated that DockContainers are created and destroyed by SandDock to accomodate my windows:

    "Why are you concerned about keeping your DockContainer? The whole point of DockContainers is that they are temporary, created and destroyed by SandDock to accommodate your windows, wherever they may be." (from the bottom of this thread http://community.divelements.co.uk/CS/forums/11465/ShowPost.aspx)

    So, I have to dig around this forum and the designer generated code to figure out how to create a dock container and layout systems. Pardon my frustration, but...coupled with the lack of any real documentation and no examples on how to do this has made it a nightmare.

    For instance, I see the designer generates this code when I add my dockable windows at design time. Is all of this really required, just to dock a window to the bottom of my form? If so, can someone explain to me what "ContentSize" is (the documentation says "It's the size of the content"...wooooo!). Also, what is the "workingSize" that is being passed to the SplitLayoutSystem and ControlLayoutSystem constructors???

    this.dockContainer1 = new TD.SandDock.DockContainer();
    this.dockContainer1.SuspendLayout();
    ...
    this.dockContainer1.ContentSize = 200;
    this.dockContainer1.Controls.Add(this.activityDetailTool1);
    this.dockContainer1.Dock = System.Windows.Forms.DockStyle.Bottom;
    this.dockContainer1.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)(this.activityDetailTool1))}, this.activityDetailTool1)))});
    this.dockContainer1.Location = new System.Drawing.Point(0, 346);
    this.dockContainer1.Manager = this.DockMgr;
    this.dockContainer1.Name = "dockContainer1";
    this.dockContainer1.Size = new System.Drawing.Size(792, 204);
    this.dockContainer1.TabIndex = 4;
    ...
    this.Controls.Add(this.dockContainer1);
    ...
    this.dockContainer1.ResumeLayout(false);
  • 01-07-2008 4:47 In reply to

    • WayneB
    • Top 150 Contributor
    • Joined on 09-06-2007
    • Posts 9

    Re: Showing UserDockableWindows at runtime is a pain (SandDock 3.0.1.1)

    I also tried to use tool.DockInNewContainer(...) to open it, but that ends up in a null reference as well because, I'm assuming, that there is no layout system??

    When and why would one use DockInNewContainer?
  • 01-07-2008 4:56 In reply to

    • WayneB
    • Top 150 Contributor
    • Joined on 09-06-2007
    • Posts 9

    Re: Showing UserDockableWindows at runtime is a pain (SandDock 3.0.1.1)

    Doing tool.OpenFloating() works fine. I don't have to add any dock containers to my MainWindow. Once the tool window is opened, I can dock it to my MainWindow by dragging it, at which point, I'm assuming, that the SandDockManager creates the necessary DockContainer and layout systems.

    So, what can I do to make the dock manager just create the necessary items when I call OpenDocked instead?
  • 01-07-2008 5:44 In reply to

    • WayneB
    • Top 150 Contributor
    • Joined on 09-06-2007
    • Posts 9

    Angry [:@] Re: Showing UserDockableWindows at runtime is a pain (SandDock 3.0.1.1)

    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!!
  • 01-07-2008 6:21 In reply to

    • WayneB
    • Top 150 Contributor
    • Joined on 09-06-2007
    • Posts 9

    Re: Showing UserDockableWindows at runtime is a pain (SandDock 3.0.1.1)

    OK, so I figured out that if I call container.BringToFront() right after I call form.Controls.Add(container), I can see my window and it is indeed docked.

    However, the bottom half of the Tabbed Documents that were already opened are now underneath my container in the z-order.

    Basically...can I have the code that SandDock is using internally to create a container for me when I drag a window into a docking position? Because this is all too much to do.

    Thank you.
  • 01-07-2008 7:53 In reply to

    • WayneB
    • Top 150 Contributor
    • Joined on 09-06-2007
    • Posts 9

    Re: Showing UserDockableWindows at runtime is a pain (SandDock 3.0.1.1)

    By the way, I'm using Visual Studio 2008 if that makes any difference to you.

    I read elsewhere on the forum that it doesn't, but just in case...
  • 01-07-2008 9:41 In reply to

    • WayneB
    • Top 150 Contributor
    • Joined on 09-06-2007
    • Posts 9

    Re: Showing UserDockableWindows at runtime is a pain (SandDock 3.0.1.1) - Resolved

    OK, sorry for all the fuss. I fixed the problem by boiling everything down to simplicity. I created a new project with one MainWindow that has no dockable windows or tabbed documents added to it at design time. Then I created one UserDockableWindow called AlertsTool and I found out that opening my custom window is as easy as doing this:

    DockableWindow window = new AlertsTool();
    window.Manager = this.DockMgr;
    window.OpenDocked(ContainerDockLocation.Bottom);

    I wish that I knew that it was supposed to be that easy, but alas there was no definitive source to show this to me. The single demo that comes with this product only shows design time setup and I couldn't find anything in the documentation about this at all.

    This is a great, wonderful product but it really needs just a few more demos to show how to use some of the advanced features and maybe a little more commentary and examples in the documentation.

    If you made it to the bottom of this thread, God bless you.

    Thank You and Good Night.
Page 1 of 1 (7 items) | RSS
Copyright © 2008 Divelements Limited
Powered by Community Server (Commercial Edition), by Telligent Systems