OnActivated is not getting called in Tabbed documents

3 posts, 0 answers
  1. F5F5F5
    F5F5F5 avatar
    7 posts
    Member since:
    Oct 2009

    Posted 30 Oct 2009 Link to this post

    Hi,
    I am using a RadDock control with AutoDetectMDIChildren set to true. I have been given forms to be hosted as tabbed documents. I do this by setting the forms' MdiParent property to the main form and then calling their Show methods. These forms override the Form.OnActivated method. This method is never called.

    Here is a simplified example:

        public partial class MdiChild : Form  
        {  
            public MdiChild()  
            {  
                InitializeComponent();  
            }  
     
            int counter = 0;  
            protected override void OnActivated(EventArgs e)  
            {  
                label1.Text = string.Format("Activated {0}", ++counter);  
            }  
        }  
     
    When I first show the form I would expect its Label1 to display Activated 1. If I click on another tab then back on this form's tab I would expect to see Activated 2 etc.

    Thanks
  2. F5F5F5
    F5F5F5 avatar
    7 posts
    Member since:
    Oct 2009

    Posted 03 Nov 2009 Link to this post

    I worked around this problem myself using reflection:

    using System.Windows.Forms;  
    using Telerik.WinControls.UI.Docking;  
    using System.Reflection;  
     
    namespace TelerikTest  
    {  
        public class RadDockManager : Telerik.WinControls.UI.Docking.RadDock  
        {  
     
            const string onFormActivated = "OnActivated";  
     
            private MethodInfo _formActivatedMethod;  
            public MethodInfo FormActivatedMethod  
            {  
                get 
                {  
                    if (_formActivatedMethod == null)  
                        _formActivatedMethod = typeof(Form).GetMethod(onFormActivated, BindingFlags.Instance | BindingFlags.NonPublic);  
                    return _formActivatedMethod;  
                }  
            }  
     
            protected override void OnActiveWindowChanged(DockWindowEventArgs e)  
            {  
                Form f = e.DockWindow.GetHostedForm() as Form;  
                if (f == nullreturn;  
     
                FormActivatedMethod.Invoke(f, new object[] { new System.EventArgs() });   
                base.OnActiveWindowChanged(e);  
            }  
       }  
     
        public static class RadDockExtensions  
        {  
            public static Form GetHostedForm(this DockWindow dockWindow)  
            {  
                HostWindow hw = dockWindow as HostWindow;  
                return hw == null ? null : hw.Content as Form;  
            }  
        }  
    }  
     
  3. Nick
    Admin
    Nick avatar
    767 posts

    Posted 03 Nov 2009 Link to this post

    Hi F5F5F5,

    Thank you for sharing your solution with the community. I have updated your Telerik points for that.

    Regards,
    Nick
    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