How to get RadForm from DockWindow?

7 posts, 1 answers
  1. Jaehong
    Jaehong avatar
    10 posts
    Member since:
    Aug 2010

    Posted 11 Oct 2010 Link to this post

    I'm using RadDock for MDI container.
    When I get active child window from RadDock.DocumentManager.ActiveDocument, can not convert RadForm from it.
    I don't know how to convert RadForm from DockWindow.
    Please, show me a good example.
  2. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 11 Oct 2010 Link to this post

    Hello Jaehong,

    To get the active MDI Child form from the ActiveDocument you can use:
    C#:
    var activeForm = ((Telerik.WinControls.UI.Docking.HostWindow)(radDock1.DocumentManager.ActiveDocument)).MdiChild;
    VB:
    Dim activeForm = DirectCast(radDock1.DocumentManager.ActiveDocument, Telerik.WinControls.UI.Docking.HostWindow).MdiChild

    If you need any more help you can check out the documentation for RadDock here and an article about Automatic MDI Form Handling in RadDock here.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Oct 2010 Link to this post

    Hi, 

    You don't have to go through the DocumentManager to get that information. this example shows setting an active form, and then finding out what the name is: 
    Private Sub Form_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        Dim form2 As New RadForm2()
        form2.MdiParent = Me
        form2.Show()
        Me.RadDock1.ActivateMdiChild(form2)
        MessageBox.Show(Me.RadDock1.ActiveWindow.FindForm().Name)
     
    End Sub

    (EDIT: Oops, sorry Emanuel - I had the reply screen opened when you already replied)

    hope that helps
    Richard
  5. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 11 Oct 2010 Link to this post

    Hello Richard, Jaehong,

    I have to contradict you on this, if you call radDock1.ActiveWindow.FindForm() it will return the parent form, please see the following example:

    Imports System
    Imports System.Windows.Forms
    Imports Telerik.WinControls.UI
    Imports Telerik.WinControls.UI.Docking
     
    Partial Public Class Form1
        Inherits Form
        Private WithEvents radDock1 As New RadDock()
        Private WithEvents CreateFormButton As New RadButton
        Private WithEvents GetActiveFormButton As New RadButton
     
        Public Sub New()
            InitializeComponent()
        End Sub
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.IsMdiContainer = True
            radDock1.AutoDetectMdiChildren = True
            Me.radDock1.MdiChildrenDockType = Telerik.WinControls.UI.Docking.DockType.Document
            radDock1.Dock = DockStyle.Fill
            Me.Controls.Add(radDock1)
     
            CreateFormButton.Text = "Create Form"
            CreateFormButton.Dock = DockStyle.Bottom
            Me.Controls.Add(CreateFormButton)
     
            GetActiveFormButton.Text = "Get Active Form"
            GetActiveFormButton.Dock = DockStyle.Bottom
            Me.Controls.Add(GetActiveFormButton)
        End Sub
     
        Private Sub getActiveFormButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles GetActiveFormButton.Click
            Dim activeForm = DirectCast(radDock1.DocumentManager.ActiveDocument, Telerik.WinControls.UI.Docking.HostWindow).MdiChild
     
            Dim form = radDock1.ActiveWindow.FindForm()
     
            If (Not activeForm.Equals(form)) Then
                MessageBox.Show("Child form is: " + activeForm.Name+ " Parent form is: "+form.Name)
            End If
        End Sub
     
        Private Sub button_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CreateFormButton.Click
            Dim form = New ChildForm()
            form.Name = "ChildForm " + radDock1.DockWindows.Count.ToString
            form.Text = "ChildForm " + radDock1.DockWindows.Count.ToString
            form.MdiParent = Me
            radDock1.ActivateMdiChild(form)
            form.Show()
        End Sub
     
    End Class
     
    Public Class ChildForm
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub
     
        ''' <summary>
        ''' Required designer variable.
        ''' </summary>
        Private components As System.ComponentModel.IContainer
     
        ''' <summary>
        ''' Clean up any resources being used.
        ''' </summary>
        ''' <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing AndAlso (components IsNot Nothing) Then
                components.Dispose()
            End If
            MyBase.Dispose(disposing)
        End Sub
     
    #Region "Windows Form Designer generated code"
     
        ''' <summary>
        ''' Required method for Designer support - do not modify
        ''' the contents of this method with the code editor.
        ''' </summary>
        Private Sub InitializeComponent()
            Me.components = New System.ComponentModel.Container()
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.Text = "Form1"
        End Sub
     
    #End Region
    End Class

    If you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
  6. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Oct 2010 Link to this post

    Hi Emanuel, 

    How embarrassing. My bad. 
    Thanks
    Richard 
  7. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 11 Oct 2010 Link to this post

    Hello Richard,

    Come on, don't worry, we all make mistakes and grow from them, in one way it would have been more logical like this, but at the moment this is not the actual behavior of the RadDock.

    Best Regards,
    Emanuel Varga
  8. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 11 Oct 2010 Link to this post

    Hi Emanuel, 
    :o)
    You're right. It would make sense. There are a few method/property names I would like to see changed and added. A direct property to the active form is now another of those  :o)
    All the best
    Rich
Back to Top
UI for WinForms is Visual Studio 2017 Ready