Jump to content

Console window problem

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
X_Programmer

X_Programmer

    Learning Programmer

  • Members
  • PipPipPip
  • 89 posts
Hey,

I'm pretty new at programming and I have a question for you guys.

I have recently started making C# forms apps without an IDE and when I compile them a console window opens up first, and then launches the program.

The problem is that the console window stays open even after the launch, and if it's closed it closes the forms app.

For example, a simple program made with the following code:
using System;


using System.Windows.Forms;


using System.Drawing;


public class Form1 : Form

{

public static void Main()

{

Application.Run(new Form1());

}


public Form1()

{

Text = "Test form";

}


}

that is compiled by linking the file to a compiler like Visual Studio through the command prompt, makes a console window pop-up in addition to the Forms window when run.

I know I'm a complete newbie, but is there a way to hide the console window without making the program with an IDE?

#2
FlashM

FlashM

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
Well, I allways use IDE to compile my application, but there might be few possibilities to resolve this. I'll take a look at how IDE does this and will let you know.

#3
FlashM

FlashM

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
OK, when compiling windows form, you have to use /target:winexe as your argument. If you specify /target:exe, a Console window will be looming in the background of your main Form.

example:
csc /t:winexe /out:MyApp.exe Program.cs Form1.cs

Hope this helps.

#4
X_Programmer

X_Programmer

    Learning Programmer

  • Members
  • PipPipPip
  • 89 posts

FlashM said:

OK, when compiling windows form, you have to use /target:winexe as your argument. If you specify /target:exe, a Console window will be looming in the background of your main Form.

example:
csc /t:winexe /out:MyApp.exe Program.cs Form1.cs

Hope this helps.

Okay, cool, that worked perfectly, thanks a lot :)