1

I would like to ask how is possible to get name of active form with using console app in C#?

I imported System.Windows.Forms; and some some DLL libraries (user32.dll and kernel32.dll) But i dont know, how finish IT.

Thanks very much for any advice.

redrom
  • 11,502
  • 31
  • 157
  • 264

3 Answers3

2

Is this what you're looking for? This should help you get the title of whatever the active window is, whether it's in your project or not.

How do I get the title of the current active window using c#?

Community
  • 1
  • 1
Nathan
  • 1,675
  • 17
  • 25
  • But if you did that, wouldn't the console window always be the active window? –  Dec 08 '10 at 21:04
  • Not necessarily, it would always be the active window if the user were using the console window (i.e. typing commands in it). But if the user, say, pulls up Notepad in front of the console window while the program is running, then Notepad would be active. The solution in the linked post is for any C# windows application, not necessarily a Console application. – Nathan Dec 08 '10 at 21:16
1

Depending on what exactly your needs are, the Console.Title static property might be what you’re looking for.

string windowName = Console.Title;

or

Console.Title = "ZONK 1-D: A New Text-Based Adventure Game!";
Jeffrey L Whitledge
  • 58,241
  • 9
  • 71
  • 99
0

One Way to get the Active form name using c# is using the following line,

    formName=this.page.GetType().ToString()

This will give form name as "ASP_Pages_Formname_aspx" and then we can retrieve the exact formname using string manipulation methods.

Deepak Kothari
  • 1,601
  • 24
  • 31