Float Existing ToolWindow

4 posts, 0 answers
  1. Jeff
    Jeff avatar
    48 posts
    Member since:
    Apr 2012

    Posted 31 May 2013 Link to this post

    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
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 05 Jun 2013 Link to this post

    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?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jeff
    Jeff avatar
    48 posts
    Member since:
    Apr 2012

    Posted 05 Jun 2013 Link to this post

    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?
  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 10 Jun 2013 Link to this post

    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?
Back to Top