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

OnActivated is not getting called in Tabbed documents

2 Answers 96 Views
Dock
This is a migrated thread and some comments may be shown as answers.
F5F5F5
Top achievements
Rank 1
F5F5F5 asked on 30 Oct 2009, 03:06 PM
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 Answers, 1 is accepted

Sort by
0
F5F5F5
Top achievements
Rank 1
answered on 03 Nov 2009, 01:13 PM
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;  
        }  
    }  
}  
 
0
Nick
Telerik team
answered on 03 Nov 2009, 01:35 PM
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.
Tags
Dock
Asked by
F5F5F5
Top achievements
Rank 1
Answers by
F5F5F5
Top achievements
Rank 1
Nick
Telerik team
Share this question
or