Home ยป Basic C# GTK program

Basic C# GTK program

by shedboy71

In a previous example we created a simple console program, in this example we will create a basic GUI program. To do this we need to install GTK.

Lets begin by installing GTK for mono

[codesyntax lang=”bash”]
sudo apt-get install gtk-sharp2
[/codesyntax]

Create a folder and a file called gtkexample as follows

[codesyntax lang=”bash”]
mkdir gtkexample
cd gtkexample
geany gtkexample.cs
[/codesyntax]

Now enter the following code

[codesyntax lang=”csharp”]
using Gtk;
using System;

class gtkHello {

static void Main()
{
Application.Init ();
Window gtkWin = new Window (“GTK Example”);
gtkWin.Show();
Application.Run();

}
}
[/codesyntax]

Now open the file manager, navigate to the gtkexample folder. This should look like this

gtk folder structure

gtk folder structure

Now double click on the gtkexample.exe. You should see something like the following

gtk window

gtk window

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More