Gtk# is a cross-platform library for graphical interfaces. To use Gtk#, you will need to install it on your system, then configure your build environment to use it.
On Linux, I recommend that you use Mono for
building Gtk# programs. If you are using Mono on Ubuntu, install the
libgtk2.0-cil
package:
$ sudo apt install libgtk2.0-cil
On macOS you don't need to install anything, since Gtk# 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" if you want to build using Mono, or "GTK# for .NET" if you want to build using Visual Studio. Run the downloaded installer.
You will need to configure your build environment so that programs include five libraries: ATK, Cairo, GLib, GDK and GTK. The exact steps depend on your operating system and development environment.
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.
Be sure that you have first installed Gtk# via the link at the top of this page.
Create a new console project.
In the Solution Explorer sidebar, right click on References and select Add Reference…
In the window that appears, click the Browse… button in the lower right corner.
Navigate to the
directory C:\Program Files (x86)\GtkSharp\2.12\lib
(or
wherever else you installed Gtk#).
Enter the
Mono.Cairo
directory. Double click on Mono.Cairo.dll
.
Click the Browse… button again.
Go up one
directory, then descend into the gtk-sharp-2.0
directory.
Double click on
atk
-sharp.dll
.
Click the Browse… button again.
Double click on
g
dk
-sharp.dll
.
Click the Browse… button again.
Double click on
glib-sharp.dll
.
Click the Browse… button again.
Double cliick on
gtk-sharp.dll
.
Click OK.
You should now be able to build a Gtk# program in the current project.
This will work on Linux or macOS. On Windows, I have not yet been able to get command-line builds to work, so instead you must use Visual Studio as described above.
First verify that these libraries are present on your system. They are probably at the following paths.
On Linux:
/usr/lib/mono/4.8-api/Mono.Cairo.dll
/usr/lib/cli/atk-sharp-2.0/atk-sharp.dll
/usr/lib/cli/gdk-sharp-2.0/gdk-sharp.dll
/usr/lib/cli/glib-sharp-2.0/glib-sharp.dll
/usr/lib/cli/gtk-sharp-2.0/gtk-sharp.dll
On macOS:
/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.8-api/Mono.Cairo.dll
/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/atk-sharp.dll
/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/gdk-sharp.dll
/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/glib-sharp.dll
/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/gtk-sharp.dll
To configure Geany:
Open any C# source file in Geany.
With the C# source file open, choose the menu item Build → Set Build Commands.
A dialog will open. In the section "C# commands", replace the entire Compile and/or Build commands with the following:
on Linux:
csc
/reference:/usr/lib/mono/4.8-api/Mono.Cairo.dll,/usr/lib/cli/atk-sharp-2.0/atk-sharp.dll,/usr/lib/cli/gdk-sharp-2.0/gdk-sharp.dll,/usr/lib/cli/glib-sharp-2.0/glib-sharp.dll,/usr/lib/cli/gtk-sharp-2.0/gtk-sharp.dll
"%f"
on macOS:
csc
/reference:/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.8-api/Mono.Cairo.dll,/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/atk-sharp.dll,/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/gdk-sharp.dll,/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/glib-sharp.dll,/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/gtk-sharp-2.0/gtk-sharp.dll
"%f"