Programmatic ToolWindow/DocumentWindow Management

Docking/MDI for Windows Forms Forum

Posted 4 years ago by EntityDev
Version: 14.1.0323
Avatar

Hello,

I'm having difficulty managing instances of DocumentWindow and ToolWindow.

I have classes inheriting each type. I have a particular object I would like to use as a tabbed document which behaves as a tool window. The best example I can cite which makes use of this paradigm is the Object Explorer Details view in SQL Server Management Studio.

It is essentially a Form, in behavior, but it is docked in the SSMS UI document container. It is available on the View menu. I need to develop a control which behaves in precisely this manner.

What I cannot determine is whether, in the DockManager environment, this object should inherit from ToolWindow, or DocumentWindow. I have tried both but cannot figure out how to properly instantiate it and get it docked into the document container. A ToolWindow can be a document, so I'm sure that's a clue for me, but I haven't determined how to get the thing rigged up. Once it's docked, it should behave as an Object Explorer Details "document", in that it should not be user-dockable as a ToolWindow, should not Float, etc., etc. I'm sure this is another clue for me - my best guess is that this object should inherit from ToolWindow.

I have added an item to the View menu.

Can I get some help in VB please, demonstrating how to achieve the above?

Thank you.

Comments (2)

Posted 4 years ago by EntityDev
Avatar

I feel like I'm on the right track:

    Private Sub ViewToolWindowMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim window = CType((CType(sender, ToolStripItem)).Tag, ToolWindow)

        Select Case window.DockManager Is Nothing
            Case True
                window.DockManager = Me.MainDockManager
                window.Activate()
            Case False
                window.Activate()
        End Select
    End Sub

 The ToolWindow in this case would be the one to which I'm assigning a DockManager (the True case). However, it appears on the Form as a ToolWindow, instead of appearing in the Document Container.

Posted 4 years ago by EntityDev
Avatar

Well, it turns out it works quite well as a Document Window instead. Please disregard the question.

    Private Sub ViewToolWindowMenuItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim tag = CType(sender, ToolStripItem).Tag

        If TypeOf tag Is ToolWindow Then
            Dim window = CType(tag, ToolWindow)

            If IsNothing(window.DockManager) Then
                window.DockManager = Me.MainDockManager
                window.Activate()
            Else
                window.Activate()
            End If
        ElseIf TypeOf tag Is DocumentWindow Then
            Dim document = CType(tag, DocumentWindow)

            If IsNothing(document.DockManager) Then
                document.DockManager = Me.MainDockManager
                document.Activate()
            Else
                document.Activate()
            End If
        End If
    End Sub
The latest build of this product (v2020.1 build 0400) was released 22 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.