0

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.

3
  • Please be more specific. Are you looking for a reference of current window within your application? Or any window system-wide? What kind of reference are you looking for? Windows handle? Or some higher-level reference (like Form instance in .NET)? Commented Apr 23, 2013 at 13:29
  • I need to know the Form name in current application which is opened. Since i can't find the right place to change the source code, it will be easy for me if i know the form name which is being shown. Commented Apr 23, 2013 at 14:54
  • Ok, see my answer. Also please update your question to make it clear what you look for. Use edit link. Commented Apr 23, 2013 at 15:05

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Actually i am having source code of a tool. This tool has many forms and some forms are generated dynamically. I need to customize the tool. When the application is running i am opening the form which needs to be customized. How to find the name of currently opened form. In web application, i can view the data source to find the current page.
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.