简体   繁体   中英

Type or namespace Window cannot be found

I am confused as to why a Window will not appear with the below code. Am I missing an import?

using System.Text;
using System.Xml;
using System.Windows;
using System;
using System.Windows.Forms;
using System.IO;
using System.Threading;

    public class Program {

    public Window mainWindow;

    static void main() {

        // Create the application's main window
        mainWindow = new Window();
        mainWindow.Title = "Enter SN";
        mainWindow.Show();
    }
    }

You want to run your Window via an Application.Run() call. Your current code will not fire it off on a standard windows message loop, which is required.

Remove your Show() call and replace it with:

Application.Run(mainWindow);

To be even simpler, if you set your title as your wish on your WinForms designer, your main can be a single line:

Application.Run(new Window());

Also, you have many unnecessary using statements. These statements aren't a real problem, just unnecessary and confusing.

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