Dock a form on the MDI parent from a child form

2 posts, 0 answers
  1. William Willson
    William Willson avatar
    3 posts
    Member since:
    Jul 2009

    Posted 29 Nov 2010 Link to this post

    Hi,

      I'm trying to figure out a good way to dock a form onto an MDI Parent RadDock from a child form.  The method I have been using is as follows:

    Dim dockOpen As Integer = 0

    For Each checkdoc As DockWindow In RadDock1.DockWindows.DocumentWindows
          If checkdoc.Name = "NameofForm1" Then
                      dockOpen = 1
          End If
    Next

    If dockOpen = 0 Then
        'Open Form
        Dim OpenForm As new NameofForm()
        OpenForm.Text = "Form Title"
        RadDock1.DockControl(OpenForm, UI.Docking.DockPosition.Fill, UI.Docking.DockType.Document)

        Dim dockable As DockWindow = GetDockableByName("NameofForm1")
        If Not dockable Is Nothing Then
            Me.RadDock1.ActiveWindow = dockable
        End If
    Else
        Dim dockable As DockWindow = GetDockableByName("NameofForm1")
        If Not dockable Is Nothing Then
            Me.RadDock1.ActiveWindow = dockable
        End If
    End If

    This works fine when I call it from within my MDI Parent form.  The problem is from my Child Form I can't see 'RadDock1' or 'GetDockableByName'.  Can anyone help me out?

    Thanks,
    Will
  2. William Willson
    William Willson avatar
    3 posts
    Member since:
    Jul 2009

    Posted 29 Nov 2010 Link to this post

    I managed to answer this myself, and found the answer in a 2009 post.  In case anyone needs this in the future, the resolution is as follows:

    Public Class Form2  
        Dim hostParent As HostWindow  
     
        Private Sub Form2_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            hostParent = Me.Parent  
        End Sub 
     
        Private Sub RadButton1_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadButton1.Click  
            If hostParent IsNot Nothing Then 
                Dim f3 As Form3 = New Form3  
                hostParent.DockManager.DockControl(f3, DockPosition.Left, DockType.Document)  
            End If 
        End Sub 
    End Class 

    Thanks,
    Will
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top