Reputation: 2097
created a c# console project, which contains a console class (program.cs). i added a form (Main.cs) to the project.
I want to do one of the below things with my project
1. Change the project to a Windows Form Application,can i change it to a Windows Form Application without creating a new project.
2. Set Main class as the startup object. Checked 'Application' tab in the properties window. The main class it not in the Startup object list.
Upvotes: 3
Views: 3897
Reputation: 941465
Things you have to do:
Rewrite the Main() method to look like this:
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new YourMainForm());
}
Change "YourMainForm" to the name of your form class. Salvaging your existing code in the Main() method is what will probably be the painful bit. You cannot leave it after the Run() call, that call won't return until the user closes your main form.
Upvotes: 7
Reputation: 13783
Change the project to a Windows Form Application Go to project properties -> "Application" tab -> "Output type" combo-box, and select "Windows Application".
Set Main class as the startup object
You don't have to set a startup object as long as you have only a single class containing a static method Main().
To run a windows application you have to implement a method Main containing a call to Application.Run()
. You can create a windows forms project with a new project wizard to see an example.
Upvotes: 2
Reputation: 73253
In the project properties, change the Output Type from Console Application
to Windows Application
.
Upvotes: 3