When we use web application, we can view the current page details by seeing the view source. In my case i need to identify the current form displayed while running windows application. Is there any way to find this. My source have many forms and some forms are generated dynamically.
2 Answers
If you are looking for currently active instance of Form in your .NET application, use Form.ActiveForm static property.
To get the form name, use Form.ActiveForm.Text. To get the form type, use Form.ActiveForm.GetType().
To have suitable place to evaluate the above, you can put following code somewhere at the beginning of the application (Main):
new System.Threading.Timer(
delegate
{
Type activeFormType =
(Form.ActiveForm != null) ? Form.ActiveForm.GetType() : null;
Type breakpointHere = activeFormType;
},
null, 0, 10000);
Then run your application, open the form you want to inspect. Switch to VS and put breakpoint on line string breakpointHere .... Switch back to your application and wait for the timer to fire and the debugger to stops on the breakpoint. Then check value of activeFormType.
1 Comment
Use Hawkeye
Hawkeye is a free utility.
It's like a dynamic property grid than can hook to any windowsform application. Once hooked to an application it will show properties, fields, type, methods...
When you hook it to a form, you'll see the form name (the object type)
Forminstance in .NET)?