This is a migrated thread and some comments may be shown as answers.

How to get RadForm from DockWindow?

12 Answers 561 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Jaehong
Top achievements
Rank 1
Jaehong asked on 11 Oct 2010, 01:33 PM
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.

12 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 11 Oct 2010, 01:56 PM
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
0
Richard Slade
Top achievements
Rank 2
answered on 11 Oct 2010, 02:01 PM
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
0
Emanuel Varga
Top achievements
Rank 1
answered on 11 Oct 2010, 02:23 PM
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
0
Richard Slade
Top achievements
Rank 2
answered on 11 Oct 2010, 02:43 PM
Hi Emanuel, 

How embarrassing. My bad. 
Thanks
Richard 
0
Emanuel Varga
Top achievements
Rank 1
answered on 11 Oct 2010, 02:46 PM
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
0
Richard Slade
Top achievements
Rank 2
answered on 11 Oct 2010, 02:49 PM
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
0
Cesar
Top achievements
Rank 1
answered on 31 Aug 2019, 11:45 PM

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'.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Sep 2019, 08:37 AM

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
0
Cesar
Top achievements
Rank 1
answered on 03 Sep 2019, 04:49 PM

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.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Sep 2019, 01:40 PM
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.
0
Cesar
Top achievements
Rank 1
answered on 04 Sep 2019, 03:56 PM
I couldn't open the code sample project because I am using 2016.3.1024.40 version. 
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Sep 2019, 06:14 AM
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.
Tags
Dock
Asked by
Jaehong
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Richard Slade
Top achievements
Rank 2
Cesar
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or