Scott Hanselman

Cross-platform GUIs with open source .NET using Eto.Forms

March 16, 2018 Comment on this post [7] Posted in Linux | Open Source
Sponsored By

Amazing Cross Platform ANSI art editorThis is one of those "Did you know you could do THAT?" Many folks have figured out that C#/F#/.NET is cross-platform and open0source and runs on basically any operating system. People are using it to create micro services, web sites, and webAPI's all over. Not to mention iPhone/Android apps with Xamarin and video games with Unity and MonoGame.

But what about cross platform UIs?

While not officially supported by Microsoft - you can do some awesome stuff...as is how Open Source is supposed to work! Remember that there's a family of .NET Runtimes now, there's the .NET Framework on Windows, there's xplat .NET Core, and there's xplat Mono.

Eto.Forms has been in development since 2012 and is a cross-platform framework for creating GUI (Graphical User Interface, natch) applications with .NET that run across multiple platforms using their native toolkit. Not like Java in the 90s with custom painted buttons on canvas.

It's being used for real stuff! In fact, PabloDraw is an Ansi/Ascii text editor that you didn't know you needed in your life. But you do. It runs on Windows, Mac, and Linux and was written using Eto.Forms but has a native UI on each platform. Be sure to check out Curtis Wensley's Twitter account for some cool examples of what PabloDraw and Eto.Forms can do!

  • OS X: MonoMac or Xamarin.Mac (and also iOS via Xamarin)
  • Linux: GTK# 2 or 3
  • Windows: Windows Forms (using GDI or Direct2D) or WPF

Here's an example Hello World. Note that it's not just Code First, you can also use Xaml, or even Json (.jeto) to layout your forms!

using Eto.Forms;
using Eto.Drawing;

public class MyForm : Form
{
public MyForm ()
{
Title = "My Cross-Platform App";
ClientSize = new Size(200, 200);
Content = new Label { Text = "Hello World!" };
}

[STAThread]
static void Main()
{
new Application().Run(new MyForm());
}
}

Or I can just File | New Project with their Visual Studio Extension. You should definitely give it a try.

image

Even on the same platform (Windows in the below example) amazingly Eto.Forms can use whatever Native Controls you prefer. Here's a great example zip that has precompiled test apps.

WinForms, WPF, and Direct2D apps

Once you've installed a new version of Mono on Ubuntu, you can run the same sample as Gtk3, as I'm doing here in a VM. AMAZING.

image

Here's some example applications that are in the wild, using Eto.Forms:

There's so much cool stuff happening in open source .NET right now, and Eto.Forms is actively looking for help. Go check out their excellent Wiki, read the Tutorials, and maybe get involved!


Sponsor: Get the latest JetBrains Rider for debugging third-party .NET code, Smart Step Into, more debugger improvements, C# Interactive, new project wizard, and formatting code in columns.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
March 16, 2018 6:32
And this is before you even get into the magic of the WebSocket Bridge which truly makes .NET ubiquitous:

https://github.com/praeclarum/Ooui

Works in both native and web scenarios, 100% code and view reuse. .NET is officially relevant again.
March 16, 2018 8:01
Really makes me happy to see Curtis' project Eto.Forms being showcased. Eto.Forms is really fantastic technology. He's done really amazing work.

Pushing Eto.Forms further, I have use Eto.Forms with OpenTK to create a C# 3D game map editor: https://github.com/bchavez/SharpFlame

SharpFlame works on Linux and Windows, but not MacOS yet (due to a bug in OpenTK not Eto.Forms). It's really great to see .NET getting very close to building 3D cross-platform apps too. :)

BTW, the Wiki link to Eto.Forms at the bottom of the post is broken. Regardless, EXCELLENT post!

March 16, 2018 8:12
Have you heard anything about https://github.com/AvaloniaUI/Avalonia ? I know they still don't have DataGrid control, but rest seems ok.
March 16, 2018 9:42
...or... use Electron?
March 19, 2018 17:23
"While not officially supported by Microsoft - you can do some awesome stuff..."

I highly appreciate the work done in Avalonia (WPF syle) and Eto.Forms (Forms sytle). I've used both for private projects with success.
But to make .Net Core relevant in the corporate world, there needs to be a UI framework officially supported my MSFT, with a guaranteed support window. We have have maintenance windows of at least 5 years, and no manager will agree to use such frameworks. If the maintainers move to the next thing, MSFT overhauls half of it's APIs gain, etc, there is a severe risk the framework is left for dead while the community moves to the next thing.
The constant changes of direction in .Net core already damaged it's reputation, and promoting community/hobbyist projects as a replacement for a proper UI framework with reliable support does not help.


March 25, 2018 19:59
Putting .NET in perspective

These days it looks like .NET 4.x is going the same way as Silverlight. Where SL was and is still something great, it s even super secure and x platform. Microsoft does not seem to realise this. Development with .NET today seems only interesting for .NET Core but be aware of the dangers which are very real:

  • Security: .NET is intrinsically not safe. This is by nature. Look up the official security bulletins and the hot fixes to backup this statements. The same thing can be said about Java. 
These updates can also break your published code. You have to fix that and you already probably did this a few times.

.Net Core (or Standard?) tries to mitigate this by providing all the included .DLLs in your exe. As a result of this .NET security responsibility is shifted from Microsoft to the developer! Well, at least you can test it before.

It is not hard to imagine that it will not take long that governments and big corp of all kinds will deny all software written in those languages because of the Java/.NET security issues. If I was a government I would. Wouldn’t you ?

  • GUI Development with MS .NET is only supported with .NET 4.x which will be obsolete soon. All other OS GUI framework are doomed to fail because it is really hard to build a cross GUI framework. You cannot put your faith in a couple of enthusiastic super nice volunteers for the long term.

The next best thing is the Xamarin package which MS acquired. Also in here there is an interesting security problem which is best explained by words spoken by Xamarin: https://blog.xamarin.com/protecting-xamarin-apps-dotfuscator/ Which tells you to obfuscate your app. What they ‘forgot’ to explain is that people can de-obfuscate your app too! See Internet for that.

What does this mean for your Xamarin app in the Android store even if you obfuscate it? Well if you have a well selling app, chances are pretty high that you find the same app with other colors and another title pretty soon! 
 

    See https://www.preemptive.com/blog for more info on protecting. 



  • ROI Microsoft promises more ROI (300%) see https://msdn.microsoft.com/en-us/library/ms953309.aspx where MS promised larger ROI if you build your application in .NET. Of course an experienced developer will not believe this. .NET changed big time every 2 years so every ROI is where the sun does not shine. I had to throw a few years down the drain.
  • Does Microsoft uses .NET itself? All of there desktop and server software is mostly written in C or C++. Think about MS Office, SQL Server. Some are .NET. Parts of Exchange server are (breaking changes in MS Exchange because of a .NET last month ). Skype is .NET but it used to work better (what did they do?). MS Offices for mobile is written in C++. Probably microsoft.com is written in .NET.



    Focus in Microsoft is on Azure. Thats why they created Visual Studio Code and added easy access Azure templates. Which is great. Azure is a nice peace of work. You have to realise that most MS efforts are focused on this. Which is all Ok.

    Will I work in .NET Core? Well yes of course when it is a suitable choice. For example a complex multiple tenancy or a local intra web Application on which I can control the updates. If you build just web sites choose WordPress (with auto updates) or for small services use NodeJs. It all works on Azure too. For mobile find something else. Really.

    In the end, it all boils down to dependencies and control. What do you as a developer control?


    Be Safe.
  • March 26, 2018 16:53
    I wasn't aware of that. That's great news!

    Comments are closed.

    Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.