Determine active child form in MDI app

4 posts, 0 answers
  1. Tim
    Tim avatar
    4 posts
    Member since:
    Aug 2007

    Posted 13 Aug 2009 Link to this post

    I am using Dock and RibbonBar (Q2 2009 release) to design a UI. I have the Dock control set to AutoDetectMdiChildren, and can easily add forms as tabbed documents. What I would like to do is change the active RibbonTab based on the active child form in Dock so that the commands match the active document.

    I thought this would be relatively easy to do, but I seem to be stuck.
    I have implemented an event handler for the ActiveWindowChanged event of the Dock control. I can obviously gain access to the DockWindow via the DockWindowEventArgs parameter. What I haven't been able to do is determine the type of form that the DockWindow represents. Basically what I would like to be able to do is something like this:

    if (DockWindow is SettingsForm) 
      // Change to appropriate RadRibbonTab 
    else 
     // do something else 

    It seems like there should be a way of doing something like this without having to iterate over the MdiChildren array and I would be at all surprised if I am looking at this the wrong way.
  2. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 14 Aug 2009 Link to this post

    Hi Tim,

    When you create and show an MDI child form, a HostWindow is created in RadDock to host the form. The form itself is set as content in the HostWindow. So, the code snippet for the desired scenario will look like this:
    void radDock1_ActiveWindowChanged(object sender, DockWindowEventArgs e)  
    {  
        if (e.DockWindow is HostWindow)  
        {  
            if (((HostWindow)e.DockWindow).Content is Form2)  
            {  
                // change ribbon tab  
            }  
        }  

    I hope this is helpful. If you have additional questions, feel free to contact me.

    Regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jonathan Hylton
    Jonathan Hylton avatar
    20 posts
    Member since:
    Sep 2009

    Posted 12 Jan 2011 Link to this post

    HI there,

    Has the naming of the Hostwindow changed in 2010 SP1? I am having issues when converting this code to VB as this is what I am trying to use:

    Private Sub radDock1_ActiveWindowChanged(sender As Object, e As DockWindowEventArgs)
        If TypeOf e.DockWindow Is HostWindow Then
                    ' change ribbon tab   
            If TypeOf DirectCast(e.DockWindow, HostWindow).Content Is Form2 Then
            End If
        End If
    End Sub

    Thanks!

    Jonathan
  5. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 12 Jan 2011 Link to this post

    Hello Jonathan,

    There is no change in the naming of the HostWindow type. Please note, however, that this type is contained in the Telerik.WinControls.UI.Docking namespace, so you need to import it:
    Imports Telerik.WinControls.UI.Docking

    I hope this helps.

    Greetings,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top