tags:

views:

52

answers:

3

Hello, I am using a winform application c#. In the application we are using Lots of UserControls and Forms.

I have a parent form, where I am using UserControl as a MainDashBoard. But for other business requirements using Forms as well. On the userControl there is a button called LoadProperties, which will load another form displaying some properties of some object.

What I want to know is that how can I find out that currently active control is UserControl or Form. Because when I am pressing the button and saying

Form1 form = new Form1();
form.MDIParent= this;
form.show();

It is loading the form, but the this.ActiveControl is giving me the button as an active control not the form.

I want to get the currently loaded form how can I do this.

Can anybody help me out...here.

Regards Shax.

A: 

Sorry I dont quite understand.

For finding out which MDI child is active use:
Form activeChild = this.ActiveMdiChild;

If you need to check what type of object an object is you can use:

if([variable] is Form)
{
}

if([variable] is Button)
{
}

Chris
+1  A: 

Every form has an ActiveControl, the control that will get the focus when the form is activated. To get the active form you should use the static Form.ActiveForm property.

Hans Passant
A: 

Just keep reference to all opened forms.

UGEEN