简体   繁体   中英

C# winforms form show cmd

I am creating a UI application in VS without using the form designer. After creating a new form and compiling everything works good. Form is rendered, but also a cmd console is rendered! Why console is rendered with form?

I create in VS empty C# project and create Program.cs and MainWindow.cs

Program.cs

/// <summary>
/// 
/// The main entry point for the application.
/// 
/// </summary>
/// <param name="args"></param>
/// 
[STAThread]
public static void Main(String[] args)
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new MainWindow());
}

MainWindow.cs

public class MainWindow : Form
{
    private Form _mainWindowForm;

    public MainWindow()
    {
        _mainWindowForm = new Form();

        _mainWindowForm.Text = "Test";
        _mainWindowForm.Width = 800;
        _mainWindowForm.Height = 700;
    }
}

Where have I gone wrong?

Create a Windows Forms Application in Visual Studio. Delete the autogenerated Form1.cs form and open the Program.cs file and do something like this:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        var myForm = new Form();
        myForm.BackColor = System.Drawing.Color.Red;
        // Do anything else to the form here in code

        Application.Run(myForm);
    }

Right click on project and select Properties option. In the Application tab You will see project output. Here you need to select Windows Application as the project output.

项目属性窗口

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM