How to get RadForm from DockWindow?

13 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. 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
  4. 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
  5. 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 
  6. 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
  7. 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
  8. Cesar
    Cesar avatar
    16 posts
    Member since:
    May 2019

    Posted 31 Aug 2019 in reply to Emanuel Varga Link to this post

    I tried this: Dim activeForm = DirectCast(radDock1.DocumentManager.ActiveDocument, Telerik.WinControls.UI.Docking.HostWindow).MdiChild

    and it shows me this error: Cannot Convert an object type 'Telerik.WinControls.UI.Docking.DocumentWindow' to 'Telerik.WinControls.UI.Docking.HostWindow'.

  9. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4004 posts

    Posted 03 Sep 2019 Link to this post

    Hello, Cesar,  

    Following the provided code snippet, I have prepared a sample project for your reference. It is seems to work as expected on my end. Please refer to the attached sample project demonstrating how it works. Is there any difference with the code in your project?

    I am looking forward to your reply.

    Kind regards,

    Dess | Tech Support Engineer, Sr.

    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Cesar
    Cesar avatar
    16 posts
    Member since:
    May 2019

    Posted 03 Sep 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Private Function FormaActive() As Object
            Dim activeForm = DirectCast(docMainMenu.DocumentManager.ActiveDocument, Telerik.WinControls.UI.Docking.HostWindow).MdiChild
            Return activeForm
        End Function

     

    This is the code that I have, but it is returning the error I described before.

  11. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4004 posts

    Posted 04 Sep 2019 Link to this post

    Hello, Cesar,    

    I have used the same code in my sample project with the latest version of the Telerik UI for WinForms suite. Is the issue reproducible in the sample project that was provided in my previous reply? Could you please specify what is the version you are using on your end since I suppose that it is not 2019.2.618?

    I am looking forward to your reply.

     

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  12. Cesar
    Cesar avatar
    16 posts
    Member since:
    May 2019

    Posted 04 Sep 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    I couldn't open the code sample project because I am using 2016.3.1024.40 version. 
  13. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4004 posts

    Posted 06 Sep 2019 Link to this post

    Hello, Cesar,    

    In order to run the application, it is necessary to use the references from the version you have installed on your machine. You can remove all references and add them anew by using the DLLs from your installation. Delete the license.licx file. After that, you should rebuild your project, close Visual Studio and open it again to make sure that no references are kept in the memory by Visual Studio.  

    Then, you are expected to run the application without any issues. I have already tested it on my end and it seems to work as expected. 

    I hope this information helps.

     

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik

    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top