Type or namespace Window cannot be found

3.1k views Asked by At

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();
    }
    }
1

There are 1 answers

6
Stealth Rabbi On

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.