|
Linux + .NET |
Linux + Mono |
macOS + .NET |
macOS + Mono |
Windows + .NET |
Windows + Mono |
---|---|---|---|---|---|---|
GTK 2 |
|
yes |
|
yes |
(yes) |
(yes) |
GTK 3 |
yes |
yes |
yes |
no |
yes |
|
Windows Forms |
no |
yes |
no |
no |
yes |
|
On macOS, you'll first need to install Gtk 3:
Install the Homebrew package manager:
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
This step will take several minutes.
Install Gtk:
$ brew install gtk+3
This step will take approximately 5 minutes.
First create a console application:
$ dotnet new console
Now add a reference to the GtkSharp package:
$ dotnet add package GtkSharp
Now you can write GTK code in your program. You may want to begin with the source code of one of the GTK programs in the lecture notes, e.g. the "Hello, GTK" program, or the circle-drawing program in the "drawing graphics" section. To build and run your program, type
$ dotnet run
Alternatively, you can create a GTK program using one of the project templates from the GtkSharp package. To do that, you'll first need to install these templates:
$ dotnet new --install GtkSharp.Template.CSharp
Now you can create a new GTK application like this:
$ dotnet new gtkapp
This application will have some features that you probably don't need, such as a user interface defined using a .glade file. You may want to delete its source files and instead use one of the GTK programs from our lecture notes.
On Ubuntu, install the libgtk2.0-cil-dev
package:
$ sudo apt install libgtk2.0-cil-dev
On macOS you don't need to install anything, since Gtk# 2 is already included in Mono and Visual Studio for Mac.
If you are using Windows, visit the Mono for Windows page, then click "Download Mono 32-bit". Run the downloaded installer.
On Linux:
$ csc `pkg-config --libs gtk-sharp-2.0` -r:Mono.Cairo.dll program.cs
On macOS:
$ csc -lib:/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0 \ -r:gdk-sharp.dll,glib-sharp.dll,gtk-sharp.dll,Mono.Cairo.dll \ program.cs
Create a new project, choosing the template "Gtk# 2.0 Project".
In the Solution sidebar, right click on References and select Edit References…
In the window that pops up, check the box beside Mono.Cairo.
You should now be able to build a Gtk# program in the current project.
Windows Forms is included in Mono (on Linux) and .NET (on Windows) by default. You don't need to install anything extra to use it.
To create a Windows Forms project in .NET on Windows, type
C:\> dotnet new winforms
By default, a Windows Forms project builds a Windows executable that doesn't produce its own terminal window and can't write output to the terminal from which it is launched. And so if you add statements to Console.WriteLine() for debugging, they will produce no output.
To allow your program to produce console output, you'll need to make two changes to your .csproj project file.
1. Change the OutputType from WinExe to Exe:
<OutputType>Exe</OutputType>
2. Add the following line before the </PropertyGroup> end tag:
<DisableWinExeOutputInference>true</DisableWinExeOutputInference>