1

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();
    }
    }
Kyle Luchinski
  • 153
  • 1
  • 4
  • 18

1 Answers1

3

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.

Stealth Rabbi
  • 10,156
  • 22
  • 100
  • 176
  • Thanks for the reply. The imports are for what is to come later in the code. I am still getting the same error about type or namespace Window cannot be found – Kyle Luchinski Nov 03 '11 at 18:15
  • @KyleLuchinski - You need to add PresentationFramework.dll to your project. – Security Hound Nov 03 '11 at 18:17
  • I assumed that 'Window' was your own custom class? If you had a missing reference, your application wouldn't compile, unless that's what you meant by "a Window will not appear" – Stealth Rabbi Nov 03 '11 at 18:22
  • @KyleLuchinski - In the future use MSDN...http://msdn.microsoft.com/en-us/library/system.windows.window.window.aspx – Security Hound Nov 03 '11 at 18:23
  • @StealthRabbi - He is trying to display a WPF Window. It is sort of obvious thats the case. – Security Hound Nov 03 '11 at 18:24
  • @Ramhound, how is this obvious? The code has using statements for System.Windows.Forms AND doesn't have usings for WPF. The OP indicates that the form doens't display, not that it doesn't compile or has missing references. The tag 'Window' certainly doesn't refer to WPF Window either. I've always found that people generally assume WinForms over WPF if neither is specified. – Stealth Rabbi Nov 03 '11 at 18:30