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

Float Existing ToolWindow

3 Answers 109 Views
Dock
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 31 May 2013, 02:43 PM
What's wrong with my code? It returns this error on the first line:
Unable to cast object of type 'Telerik.WinControls.UI.Docking.HostWindow' to type 'Telerik.WinControls.UI.Docking.ToolWindow'.

For Each ToolWindow As Docking.ToolWindow In RadDock1.DockWindows.ToolWindows
    If ToolWindow.Name = "FormActivityDetailEdit1" Then
        Dim MyLocation As Point
        Dim MySize As Size
        MyLocation.X = 50
        MyLocation.Y = 50
        MySize.Width = 1090
        MySize.Height = 700
        ToolWindow.Float(MyLocation, MySize)
    End If
Next

3 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 05 Jun 2013, 08:20 AM
Hi Jeff,

Thank you for writing.

It seems that you have some HostWindows in the collection which you are attempting to cast to ToolWindows, thus the observed exception. Such host windows might be MDI children added to RadDock for example.

To overcome the error, you can iterate the collection by using DockWindow instead of HostWindow and then only if you find a ToolWindow, cast to it and call its Float method:
For Each ToolWindow As DockWindow In radDock1.DockWindows.ToolWindows
    If ToolWindow.Name = "test" AndAlso TypeOf ToolWindow Is ToolWindow Then
        Dim MyLocation As Point = Nothing
        Dim MySize As Size = Nothing
        MyLocation.X = 50
        MyLocation.Y = 50
        MySize.Width = 1090
        MySize.Height = 700
        DirectCast(ToolWindow, ToolWindow).Float(MyLocation, MySize)
    End If
Next

I hope this helps.
 
Regards,
Stefan
Telerik
RadChart for WinForms is obsolete. Now what?
0
Jeff
Top achievements
Rank 1
answered on 05 Jun 2013, 07:32 PM
Maybe this is my problem. I am adding forms that have already been designed as MDI children and using the dock's AutoDetectMdiChildren=True to place them in the dock. 
I use this code:
Dim IsItOpen As Boolean = False
For Each window As Docking.DockWindow In FormMain.RadDock1.DockWindows.ToolWindows
    If window.Name = "FormActivityDetailEdit1" Then
        IsItOpen = True
    End If
Next
If IsItOpen = False Then
    FormMain.PanelLoading.Visible = True
    Application.DoEvents()
    Dim MDI As New FormActivityDetailEdit
    MDI.MdiParent = FormMain
    MDI.Show()
    FormMain.AddOpened = True
End If

I suppose there is a better way for me to add these ToolWindows. How should I add these ToolWindows so that they behave properly?
0
Stefan
Telerik team
answered on 10 Jun 2013, 06:34 AM
Hi Jeff,

This is the correct way of handling MDI windows with RadDock. It is just that such windows are using the HostWindow type not the ToolWindow, thus you will have to check for both.

I hope this helps.

Regards,
Stefan
Telerik
RadChart for WinForms is obsolete. Now what?
Tags
Dock
Asked by
Jeff
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or