Should I rewrite GUI with GTK+ instead of WinForms for Mono?

16,738

Solution 1

Honestly, you're going to need to tell us more about your audience/intended market to provide a great answer, but my $0.02 from some experience developing there is that GUI development for Mono on the desktop is a multi-target affair if you want to do it "Right". You're going to need to develop the shared backend exceptionally modularly, and then write UI once per platform.

Windows

Windows.Forms as implemented on Mono is a great crutch if your app's in its infancy, allowing you to target Windows immediately and deploy in a somewhat crippled fashion on OS X and Linux. Note, however, that I've been told on IRC that Windows.Forms development on Mono is essentially dead. Old bugs don't get updated, and, as a for instance, I ran into SelectionBackColor not working in RichTextBox on OS X (it's a problem in a lib Mono uses for Windows.Forms on OS X) within a few minutes of testing. Neat that it's there, perhaps good for quick utilities where you can code around its limitations (see question here for an example).

OS X

For targeting OS X, if you have a real, commercial, end-user app, you're going to need to get used to, um, interfacing with Interface Builder. I should make clear here that using XCode and Interface Builder absolutely requires that you have access to a box running OS X. Otherwise, you're stuck with Windows.Forms or, preferably, I think, Gtk#.

Xamarin has done a great job making its IDE stub out connections to native UIs built in XCode. That's how they do it for iOS development as well. It works fairly well, though the documentation is weak. There's a great video from 2011 from Michael Hutchingson describing this process, though I suppose it's getting long in the tooth (ie, "old"). (Direct link to video)

I'm assuming Interface Builder is also your only real choice if you want to target the Mac App Store. But look, it's a native UI that's stubbed to your C# code, which is, all things considered, a great compromise.

Linux

I haven't really targeted Linux. Seems like Gtk# would be a natural fit, but I'm not much hands-on help there. My stuff builds in Windows.Forms, and there are rough edges, just like in OS X. If I got more serious, I would start with Gtk#, and that's where MonoDevelop has its GUI RAD as well.

Example of a serious, mature, crossplatform Gtk# app

Quick note: Banshee uses Gtk# to target OS X, Windows (alpha), and Linux. You can get some great context for how difficult it is to use Gtk# on a large application cross-platform by checking out its mailing list and other resources.

Sorry the news isn't any easier. There is no silver bullet/single right answer.


201607 UPDATE: I think the answer is slowly becoming to use Xamarin.Forms to target cross-platform. You might still be stuck writing a separate Mac interface for now, but there's reason to believe that'll have Xamarin.Forms support at some point too; see below.

Unfortunately, if you're targeting Linux, I think you're still in the same boat as you were before for now.

  • Windows: You can now use Xamarin.Forms and UWP.
  • macOS: You're still in essentially the same place, but I had a Xamarin employee tell me last weekend that Xamarin.Forms is unofficially in development for OS X. I believe this is the repo on GitHub. (There's even a branch for tvOS.)

Solution 2

I would suggest that you consider what your target audience is. Writing UI using a framework like GTK# might seem a good idea but to the average user your application won't look like their other Windows/OSX applications which easily can stop people from using it (unless it's really exceptional in some other way).

The best way to do this (which might not be possible due to time/budget constraints) is to put your application logic in a separate assembly and then write UI for each platform, using Winform (or WPF) for Windows, MonoMac/Cocoa for OSX and GTK# for Linux. It also won't limit you to using features that are available on all platform which would degrade the user experience a lot.

Solution 3

I'm facing a similar problem now - but what Karl-Johan said about keeping application logic separate will make the task much easier. Look into a ViewModel pattern (MVVM), and you'll have much less code to rewrite and test for each platform, as the central logic becomes UI agnostic.

Share:
16,738
Gintas_
Author by

Gintas_

Updated on June 05, 2022

Comments

  • Gintas_
    Gintas_ almost 2 years

    I was making an application with Visual Studio, winforms and I'm using openTK. Recently I thought about making it cross-platform. I'm going to use Mono, because I don't know anything else similar. And I have totally no experience with GTK+. In my application, currently there are 4 windows(of course there will be more in future). I want to make application fast in Windows, Linux and OS X. I have read, that GTK+ is better than WinForms, but still not sure which to choose. So, should I remake everything for GTK+ or stay with WinForms and why? Also, is there any tool, which would do this work for me?