tags:

views:

29

answers:

1

I mean that Visual C# can make a windows form app easily, but i want to know how C# can make WFA (because Visual C# just is a ide). how a Windows Application(not Console) can run in windows.

+2  A: 

Well, you write exactly the same code as normal, but compile with:

csc /target:winexe (source files)

Of course if you've written everything in Visual Studio, you'll have designer files - but you can write everything manually. Here's a small WinForms Hello World app:

using System;
using System.Windows.Forms;

public class Hello
{
    [STAThread]
    static void Main()
    {
        Form form = new Form
        {
            Text = "Simple Windows Forms app",
            Controls = { new Label { Text = "Hello, world" } }
        };
        Application.Run(form);
    }
}

Having mentioned the target switch earlier, I should point out that you don't have to use it - you can compile and run the code above using just

csc Hello.cs

I sometimes find that handy if I want to write a small test app which sends diagnostics to the console. It will start as a console app but still displays the form perfectly well.

Jon Skeet
Please Google (1) C++/Visual C++ (2) C#/Visual C#(what's this?)/Visual Studio
Danny Chen
@Snoopy: Um, that *is* C#. The compiler comes up saying "Visual C#" but it doesn't require Visual Studio to be installed or anything like that. In fact, I've just tested that code on the machine I'm using, which currently doesn't have VS installed.
Jon Skeet
using System.Windows.Forms -> Is it a Netframework component?
Snoob
@Snoob: Yes. Just as System.Int32, System.String etc are .NET types.
Jon Skeet
How C#/C++ can make a native windows app without Net ? (or without using System.Windows.Forms;)
Snoob
@Snoob, by using the Win32 API directly and invoking that.http://en.wikipedia.org/wiki/Windows_API
Filip Ekberg
Thanks Filip Ekberg very much. Now i knew
Snoob
@Snoob: Note that that will work for native C++, but *not* for C#.
Jon Skeet