views:

800

answers:

6

Let's say just for the joy of it, I decide that I don't want to write desktop applications in Java any more, instead want to switch to using C#. I want to be able to build an application that will run on some mainstream Linux distribution, and a recent release of MS Windows. It will have a GUI component.

In Java I can build an application that uses Swing. Once I have it working, I can copy that jar file from Windows to Linux or vice versa, depending where I developed it. And it will generally run with java -jar myapp.jar.

In C# is it possible to do this? Is there a functional equivalent to Swing or AWT in C#?

+3  A: 

You can try WxWidgets. It has support for C#, among many other languages, and is cross-platform. The only downside being a recompile for each platform. Alternatively you can try Mono which is very good, but beware there are a couple snags with compatibility issues. There is no predefined "run anywhere" file for C# apps yet like Java has with jars though, you're best bet is to recompile for each platform if you want to ensure compatibility.

John T
+3  A: 

The closest thing I've ever seen is Mono - though it doesn't support all the CLR libraries yet I believe, but it is cross-platform.

Sam Schutte
+5  A: 

I believe a good portion of WinForms is implemented in Mono. You need to install Mono under Linux for that. You may have compatibility problems, though, since Mono is not a Microsoft effort and is not officially supported by them.

unforgiven3
Yes, but it is a very *good* community effort, and I've only seen compatibility problems when I was doing something completely ridiculous (comments are too short to describe :D). Normal desktop programming is usually just fine.
Lucas Jones
@person-b, I agree, it is a very good community effort :-)
unforgiven3
As far as i am aware all of WinForms 2.0 is implemented.
Gary Willoughby
WinForms really? That's interesting. When last I checked a few years ago, there was nothing.
Jay R.
As far as i am aware all of WinForms 2.0 is implemented.
Gary Willoughby
@Jay: key phrase there is "a few years ago" mono is still a very active project.
Joel Coehoorn
The only thing missing from the Mono WinForms implementation is support for ActiveX controls when running on platforms other than Windows (for obvious reasons). So long as you don't use such controls, you're fine.
Chris Charabaruk
+10  A: 

Probably GTK# would be the closest.

I know others have said mono, but that's not quite right. .Net is to mono as Microsoft's Java VM is to Sun's Java runtime. mono's not really in the same conceptual space as Swing. For that, GTK# is a closer match.

Joel Coehoorn
I know what you're saying, in his question he asked about AWT or Swing - but what I think he's really asking is "how can I write cross-platform C# apps?".
Sam Schutte
+3  A: 

This page has a list of the GUI toolkits supported by Mono, including pros and cons for each of them. As others have suggested, WinForms, GTK#, and wxNet are all viable options.

Greg Campbell
+1  A: 

Windows.Forms is the standard library for developing GUI applications for .NET

Despite of being very well supported on Windows, version 2.0 is fully implemented by Mono too, which makes it available on all platforms supported by Mono.

WPF on the other hand is is conceptually new library, for now it is fully supported mainly on Windows only and just a subset of it supported by Mono by their Silverlight implementation - Moonlight.

If you are building application for productive cross-platform use and/or have conservative performance constraints go Windows Forms.

If you want to experiment and learn something new or if you are developing new application for Windows go WPF. This is the new technology for client GUI applications.

devdimi