views:

369

answers:

0

I have a MDI Parent, with several children, using DotNetBar component and Ribbon on the main form.

I have a sidebar required for some of the MDI children, but different one from another, so in the MDI Children "Cajero" I need some buttons and on the other I need some others, and when, Cajero closes I want to hide that sidebar.

The problem is, I found the MdiChildActivate event on the main Form (MDI parent), which raises when any form shows and when it closes. But I need to know WHICH form it is, and if it is closing or opening.

I have the following code:

    void Principal_MdiChildActivate(object sender, EventArgs e)
    {

        if (sender.GetType() == typeof(Cajero))
        {
            if (!((Cajero)sender).Focused)
            {
                this.sideBar_Opciones.Hide();
                MessageBox.Show("Sender: " + sender.ToString() + sender.GetType().ToString() + "\nEventArgs: " + e.ToString());
            }
        }
    }

Where Principal is the MDI Parent and Cajero is the child. But I run into several problems here: sender.GetType() is NEVER the same as typeof(Cajero), even when I read in several blogs and web pages that it must be the same, and is Cajero the one who's opening or closing.

And ((Cajero)sender).Focused) isn't evaluated, and when I tried to force to evaluate like changing the first IF to if( 1 == 1 ) so it always evaluated, the code raises an exception saying that it cannot be cast sender into Cajero, because the real sender is Principal.

So, how do I know which is the form closing/opening and, if it is opening or closing?