Introduction and Background
I took a more than necessary break in posting the content and articles for Ubuntu programming in C#. Anyways, I am continuing from the same place where I left and as I already taught we were at the final stages of sharing the guide for programming C# on Ubuntu; which can be thought of as a Linux environment. The previous posts can be found easily on my blog and on some of the networks that I support.
Previously, we had already talked about NuGet gallery packages, cryptographic helpers and much more. Whereas, in this post I am going to walk you people through using Windows Forms framework on Mono framework.
Windows Forms framework
Now, who doesn’t know Windows Forms framework in today’s world? If you have ever wanted to or have developed the C# programs or .NET applications then you are already familiar with Windows Forms application. Windows Forms is an old framework with graphical capabilities, and has been in the game for a more than a decade by now! It has started to get replaced by Windows Presentation Foundation, but nonetheless, it is still very popular and is being used widely by many software developers and many software development companies are still relying on it.
There are many benefits of using Windows Forms in your regular development teams,
- It supports graphics, not just the CPU and RAM processing.
- It can be used with resources for localization support is excellent.
- Provides a better way for drawing graphics on canvas.
- Event handling, delegate generation.
- Asynchronous programming patterns.
- Good data binding support provided.
I am going to provide you with some good references that you can use to learn more about Windows Forms, if sadly, you have no idea about the Windows Forms framework. However, one thing is for sure. Using Windows Forms is one of the easiest ways of building the graphical applications in ,NET environment.
References
Follow the following links and learn more about Windows Forms:
Graphical applications in Mono Project
We have until now, discussed and learned how to build small programs and some very common applications that use special kind of algorithms, such as cryptographic helpers which can be used to encrypt and decrypt the data in Ubuntu using C#. Now, until this we haven’t covered graphical applications development in Mono, because that is where this framework lags behind. So, in this post we would like to learn how to build applications with graphical capabilities too. But, first, let’s talk about the frameworks provided in Mono Project itself.
- GTK#
Which is a similar one to the GTK+ that C++ programmers have. This is a graphical toolkit that compiles down to the native code generation. It supports the native look and feel and can be used. But, it is somewhat difficult to learn!

Figure 1: GTK# control application example
- Windows Forms
This is the topic that we are going to cover in this post.
- Other tools?
Not yet, Mono Project is not ready to implement other frameworks yet.
The thing is, Mono Project doesn’t have an excellent UI designer as we have in Visual Studio.

Figure 2: Visual Studio UI Designer
In Mono Project and Xamarin Studio, you are not provided with the similar tools until now. However, the designer is just the wrapper around the back-end code available. Xamarin Studio does have a good designer, but that works with GTK# tools and controls only. Not in the case of Windows Forms.
Applying a quick hack!
If you have ever programmed for Windows Forms, then you will know that Windows Forms is actually a bunch of objects with many fields and properties, which run and work to render the graphics on the screen. The same is applicable here. We would be using the codes to render the stuff on the screen. Basically, everything that you have on the screen is a field in the backend class, such as “Button”, “TextBox”, and “Label” etc. These are all going to be used, but, we are going to write the codes for this, instead of having a designer build them up for us.
Building the UI with Windows Forms
So, I hope using the hack is clear to you, after all, it is not a hack it is the actual way in which Windows Forms applications are constructed, built and executed. Only difference is that on Windows we also get to use the UI designer. In case of Mono Project, we would have to craft the UI with our own codes and then re-implement it if there is a changing to be performed on the screen later. Thus, putting it simply, we are going to implement it the hard way since there is no, “Drag-and-drop” method here.
To get started, you need to understand that a Windows Forms application is a C# application too. So, only thing to understand is C# language itself and the .NET framework. We are going to use the same concepts of .NET framework and then implement the same concepts to Mono to get our graphical applications ready.
Create project - any type
I have chosen to build this application on the top of Console application. You can select other types too. But, my recommendation is using the Console application.

Figure 3: Selecting the console project as the type
Enter the names and details and create the project.

Figure 4: Entering the details for the project
At this moment, you will be at the same stage where you were in the beginning of this module, and the previous ones. You will have an empty project that only renders, “Hello world”. That is the start, from here we will continue to build the larger and complex stuff.

Figure 5: Hello world!
This program is the default program that every time we were shown. Now, we need to add the graphics to the console. That’s simple. All we need to do is Read the next section.
Adding graphics to the console
Adding the graphics to the console is pretty much simple, you just need to do the trick as:
- Include the System.Windows.Forms namespace to the project.
- Include the System.Drawing namespace to the project.
- Import the packages to your source code.
- Write the code yourself; since we do not have the designer.
- Run the program, and you will see the program start up.






Gowtham RajamanickamPosted Apr 2, 2016, 12:32 PM
Good one..
Kashif SohailPosted Mar 21, 2016, 10:43 PM
There is no Drag and drop functionality available there?
Vignesh ManiPosted Mar 21, 2016, 9:25 AM
Nice
Jaipal ReddyPosted Mar 21, 2016, 7:32 AM
Nice. .
Mohammed IbrahimPosted Mar 21, 2016, 5:12 AM
nice
Humayun Kabir MamunPosted Mar 21, 2016, 5:10 AM
Nice...
Debasis SahaPosted Mar 21, 2016, 4:02 AM
Good One..