Saturday, December 08, 2007

Compiling C# + gtk 2 + glade 2 on Ubuntu 7.10

Before that you need to install these packages :

And also your favorite text editor or IDE.
Create a new file GladeApp.cs with the source-code below.

using System;
using Gtk;
using Glade;

public class GladeApp
// declare the widgets you will use from glade
Gtk.Entry MyEntry;

public static void Main (string[] args)
new GladeApp (args);

public GladeApp (string[] args)

Glade.XML gxml = new Glade.XML ("", "MyWindow", null);
gxml.Autoconnect (this);

// Connect the Signals defined in Glade
public void OnMyWindowDeleteEvent (object o, DeleteEventArgs args)
Application.Quit ();
args.RetVal = true;

public void OnMyButtonClicked(object o, EventArgs args)
Console.WriteLine("In entry: " + MyEntry.Text);

Then, start your Glade.
Build a simple window with a text entry and a button. It will be looked like this :

With additional event & signal. delete_event event for MyWindow

and clicked signal for MyButton.

Saved the glade file as . You may need to learn a little bit to create these user-interface. Please keep trying.

Then you are ready to compile our code.

myprompt: mcs -pkg:gtk-sharp-2.0 -pkg:glade-sharp-2.0 GladeApp.cs

And run our application.

myprompt: mono GladeApp.exe

Post a Comment