Intro to GTK with C#

Written By: James Williams

- 10 May 2006 -
















Description: Why would anyone want to use GTK# when they can use Windows.Forms? It's cross-platform and more complete than the Mono implementation of Windows.Forms. GTK is also ingrained in the Linux community as the basis of one of the popular user interface systems, GNOME.

  1. Hello World
  2. Event Handlers
  3. On to the Code
  4. Delegates

What is it?

GTK+, the GIMP Toolkit, is a popular graphical user interface system created for the ubiquitous open-source image editor GIMP and the C programming language. Thanks to platform bindings, its interface is accessible to many other programming languages such as Java, Ruby, Python, and all .NET languages among others. Glade is a interface designer for GTK+ which stores the created layouts in XML format therefore being platform-independent and consumable by any language with an appropriate binding.

Hello World

We are going to design the interface for a simple "Hello-World"-style form with a button, a label, and a menu bar.

Go ahead and open Glade, making sure the these windows are displayed. Add a window by clicking the window component from the palette.

Click Here To View A Screenshot

Click Here To View A Screenshot

Click Here To View A Screenshot

Click Here To View A Screenshot

Layout in Glade takes a little more planning than that of your usual GUI designer. You cannot just drop in components as you would with Visual Studio or NetBeans. You must first partition the window into horizontal and vertical boxes, each of which can be further partitioned. That being said, let's partition the window for our components. We'll need three vertical boxes.

Click Here To View A Screenshot

Click Here To View A Screenshot

Click the menu bar component from the palette and click the top box.

Click Here To View A Screenshot

We don't need all these options so click the menu, then the Widgets tab of the Properties windows and click "Edit Menus." Delete all menu items so it looks like the screen capture:

Click Here To View A Screenshot

Click Here To View A Screenshot

On the right side of the window, we can see each menu item's respective label, or how it will display in the application, its variable name and the event handler. There are other useful things there but we are only concerned with these for the moment.

Next >>