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
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;
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
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
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
How embarrassing. My bad.
Thanks
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
: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
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'.
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,
the Telerik team
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.
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
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