Create ToolWIndowContainer / WinForms

Docking/MDI for Windows Forms Forum

Posted 2 years ago by Reinhardt Software GmbH - Reinhardt Software GmbH
Version: 21.1.1
Avatar

Hi Support Team.

I need to do the following:

- Find out, whether there is a ToolWindowContainer present, which is Docked on right side of screen and set to Auto Hide

- if so, I need to activate a new ToolWindow within this container

- otherwise, I need to create such Container (right side, auto hide) and then activate the new window.

My first issue is, that I do not know how to iterate through all ToolWindowContainers (couäd not find any property in DockManager), and that I could not find any samples on how to create and activate a new ToolWindowContainer.

Any help would be much appreciated.

Best regards

Marc

Comments (2)

Answer - Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Marc,

The AutoHideContainer instances (which hold a ToolWindow in auto-hide mode) are created on the control which is hosting DockManager. I put together a sample function to illustrate getting the AutoHideContainer for a particular side.

/// <summary>
/// Gets the AutoHideContainer, if any, on the given side of a DockManager.
/// </summary>
/// <param name="dockManager">The DockManager to examine.</param>
/// <param name="dockStyle">Indicates the left, top, right, or bottom side.</param>
/// <returns>An AutoHideContainer if found; otherwise false.</returns>
private AutoHideContainer GetAutoHideContainer(DockManager dockManager, DockStyle dockStyle) {
    // Make sure the DockManager is hosted
    if (dockManager.HostContainerControl != null) {
        // Iterate all the controls on the host control
        foreach (var control in dockManager.HostContainerControl.Controls) {
            // Is the control an AutoHideContainer?
            if (control is AutoHideContainer autoHideContainer) {
                // Is the AutoHideContainer on the desired side?
                if (autoHideContainer.Dock == dockStyle) {
                    return autoHideContainer;
                }
            }
        }
    }

    // Not found
    return null;
}

Then you could perform logic on your ToolWindow based on the presence of that AutoHideContainer.

// Create a new ToolWindow
ToolWindow toolWindow = CreateNewToolWindow();

// Look for an AutoHideContainer on the right side
var rightSideAutoHideContainer = GetAutoHideContainer(this.dockManager, DockStyle.Right);
if (rightSideAutoHideContainer != null) {
    // Attach to the right side AutoHideContainer
    toolWindow.DockTo(rightSideAutoHideContainer, DockOperationType.Attach);
}
else {
    // Dock to the right of DockManager
    toolWindow.DockTo(dockManager, DockOperationType.RightOuter);
    // Change the state to auto-hide
    toolWindow.State = ToolWindowState.AutoHide;
}

// Activate the new tool window
toolWindow.Activate();

This should get you what you were looking for if I understood the request correctly. Please reach out if it does not.


Actipro Software Support

Posted 2 years ago by Reinhardt Software GmbH - Reinhardt Software GmbH
Avatar

Dear Support Team,

thank you very much, works great. Excactly what I was looking for.

Best regards

Marc

The latest build of this product (v23.1.2) was released 23 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.