Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to run windows form application in console application in c#, but i didn't know how to do it

What I have tried:

I haven't nothing try anything yet
Posted
Updated 10-Jun-16 20:41pm

It's not clear what do you mean by this "run in".

First of all, strictly speaking, there is no such thing as classification of applications into "console" and "window" applications. Microsoft just present things in a misleading way.

So, you just need to know how to run one application by another application. You need to understand that you start two different processed. You can use System.Diagnostics.Process.Start:
Process.Start Method (System.Diagnostics).


Now, about project output type. With .NET, this is always a .NET assembly.

There is one important point which is expressed in Visual Studio in a very confusing way.

To reveal it, you can do one simple thing: create a Forms application or a WPF application is some standard way, say, using a standard/default project template. Run it. You will see some UI. Now, look at the project Properties, first tab "Application". Look at the option "Output Type". In all cases, it will be "Windows Application".

Now, what happens of you change it to "Console Application", not changing anything else? What would you expect? Will the windowed UI disappear? No, nothing like that. The UI won't change. Only the application will show, in addition to the form or a window… a console. If you write some console output using the object System.Console, it will be shown.

Why so? this is because "Console Application" really means "Show console". And "Windows Application" does not really mean that some windowed UI will be shown. In reality, it simply means "Don't show the console". Line the in the previous experiment, the other way around, you can start with "Console application", and then add required referenced assemblies, create a window or form in the entry-point method and execute Application.Run (of either Forms of WPF library).

Essentially, or functionally, there are no three output types. The output options can be classified into "Library" and "Application", and the "Application" has option "Show console". Microsoft decided to classify all these option in three formally equivalent output types and not explain what it means properly. And this is not just the studio; if you build projects using just the compile, the options are the same. Microsoft people did not care that many would be confused, because it doesn't matter for most; you can see how it really works if you 1) really understand the background; 2) try to create a windows application with a console, 3) try to create non-console application without any forms or windows.

However, I always prefer to know. :-)

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900