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
2010-07-23 05:47:13
Please Google (1) C++/Visual C++ (2) C#/Visual C#(what's this?)/Visual Studio
Danny Chen
2010-07-23 05:52:16
@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
2010-07-23 05:53:02
using System.Windows.Forms -> Is it a Netframework component?
Snoob
2010-07-23 05:53:11
@Snoob: Yes. Just as System.Int32, System.String etc are .NET types.
Jon Skeet
2010-07-23 05:54:49
How C#/C++ can make a native windows app without Net ? (or without using System.Windows.Forms;)
Snoob
2010-07-23 05:56:05
@Snoob, by using the Win32 API directly and invoking that.http://en.wikipedia.org/wiki/Windows_API
Filip Ekberg
2010-07-23 06:03:53
Thanks Filip Ekberg very much. Now i knew
Snoob
2010-07-23 06:07:30
@Snoob: Note that that will work for native C++, but *not* for C#.
Jon Skeet
2010-07-23 06:10:43