Recently I moved my main home PC and Laptop over to the Linux Mint distribution, which for someone who has been a dedicated Windows users since I ever got my hands on a PC back around 1990, has gone amazingly well. My next little venture is to do a little cross platform development. Although I have moved away from Windows (not strictly true as I have set up Windows 8 in a Virtual Box environment in-case I need to switch over for something) I still really like the .NET environment and C# language, so I would like to carry on using it. I would like to learn another language like Python / Ruby, but I really don’t have the time at the moment as I have just changed job and I also have young kids at home which takes up a lot of my spare time.
Thankfully, there is the Mono .NET implementation that I can use and it is really well supported. Mono is a Free (as in freedom) implementation of the C# language and .NET runtime that is written to the ECMA-334 open specification. As well as being open source, Mono also has a company, Xamarin, sponsoring its development as they use the mono system for their IOS and Android application development system, of which you can also use for free (within limits).
My main interest at the moment is writing desktop applications for both Linux and Windows. Mono does support Windows Forms, but it isn’t as well supported as the Linux Gnome user interface library GTK. Mono has a version called GTK# and it is designed to be cross platform so you can use it with Windows and Mac OSX as-well.
My SafePad and Text Shredder applications where both developed using the Windows Forms library and they both run perfectly fine under the Mono Runtime on Linux. The user interface rendering looks a little odd on Linux as it is a Windows UI library, but the applications fully work.
For my first cross platform test I decided to write a very simple application, a basic text editor. I started the application during my lunch break at work, so I started the development using Xamarin Studio under Windows 7 on my work computer, and then did the 2nd half of the development using MonoDevelop under Linux Mint at home.
Xamarin Studio is essentially MonoDevelop with a little re-branding from the Mono Project sponsor. Xamarin Studio is the main development IDE if you want to use .NET to create IOS and Anroid .NET applications. Apart from the cosmetic differences, this IDE is the same as MonoDevelop under Linux. To create a desktop application, you select a GTK# application under C# when you create a new solution. Mono Develop even includes the Stetic Form Designer so you can visually create your forms.
Creating forms isn’t as straight forward as the Windows Forms designer under Visual Studio as all the controls have to be constrained in containers, where as they don’t under Windows Forms. Once you get used to this, then the form designer is quite straight forward. For this simple little text editor I had to put a Vbox control on the form first which split the window into 3 sections. I then inserted a 4th section, by right clicking on one of the panels and selecting insert. In the top section I placed the menu. Under that a toolbar. Below that a text box window, and below that a status bar.
The menus were easy to define as where the buttons on the toolbar. You can also add icon graphics from the standard gnome icon library. When developing under Windows, your application builds and runs against the standard .NET runtime. Here is the text editor application running under Window 7.
Xamarin Studio / Mono Develop is quite a nice IDE to use. I was pleasantly surprised, but what if you still want to use Visual Studio. Well you can. Xamarin Studio created standard Visual Studio solution and project files, so the project loaded up, built and ran fine.
What you don’t get though is the Stetic Forms Designer. If this is a deal breaker then just stick with Xamarin Studio / Mono Develop for building your forms. The other option is hand coding your user interfaces, which some people will probably prefer. I know some Windows Forms developers who don’t use the form designer and hand crank all their UI code. As well as working in Visual Studio, you can also load up the solution and run it from Sharp Develop. MonoDevelop is actually based on a fork of the SharpDevelop code-base to allow it to be made cross platform.
I did the 2nd half of the development for this test application in MonoDevelop in Linux itself. Everything worked straight out of the box when I transferred the source code over. Below is a screen-shot of the application running.
Visually the application is similar, but it has more of the gnome feel to it. Especially with the icons. MonoDevelop functionally is the same as Xamarin Studio and includes the same Stetic Forms Designer.
To install MonoDevelop under Linux is very straightforward. You need to install the mono runtime, and monodevelop. This can be done via the software manager or via the command line with:
sudo apt-get update
sudo apt-get install mono-complete
sudo apt-get install monodevelop
Although this is a very simple test application is has helped me get used to the programming environment for Mono under Linux and serves as a good introduction to basic GTK# development. For my first larger project, I am planning on changing my SafePad application to use GTK# instead of Windows Forms. Even though the application runs perfectly well in it’s current state under Linux, I think that now I would feel better if it was using GTK# as this will pave the way for some more cross platform development work.
You can download the source files for this test application from here.