Click here to Skip to main content
Click here to Skip to main content

Glade Code Changer

, 18 Jul 2007
Rate this:
Please Sign up or sign in to vote.
This article introduces a code generator for Glade that produces C# code

Screenshot - GSwindows.jpg


This program is a code generator for Glade that produces C# code. It will make it nearly as easy for you to develop a cross-platform GUI with Gtk as it is with Windows Forms. The generator has been tested on both Windows and Linux with Mono.


To be able to run Gtk# GUIs on Windows, you need the Gtk# runtime. You can get it here; it is 23.3 Mb. The GUI designer Glade can be downloaded here. Alternatively, if you have Mono for Windows installed, it is under Start-> Mono 1.2.4 for Windows -> Applications -> Glade. If you are using Linux and are interested in this article, I presume that you already have Mono installed and that you are more familiar with this topic. Thus, I will explain in more detail for Windows users.

Cross-platform GUIs: left Linux and right Windows

How does it function? The tool is pretty simple. It watches the *.glade file that you selected in the upper file chooser for changes. A change in this case means that you saved it in Glade. So, when it detects the change it parses the Glade file for widgets and signals. Then it puts them into your code as specified in the *.cs file in the second file chooser. I will later go into more detail.


I am now going to explain the procedure for VS 2005. After you have downloaded and installed the Gtk# runtime, download GladeSharperTemplate and put the ZIP file like it is (unzipped!) in the directory: My files\Visual Studio 2005\Templates\Project Templates. Start VS and begin a new GladSharperProject from the templates. The main file looks like this:


    publicclass GladeApp
        staticvoid Main(string[] args)

        publicGladeApp(string[] args)
            stringstandardNamespace = 
            Glade.XMLgxml = 
                new Glade.XML(null, 
                standardNamespace + "." + "", null, null);

Now download and start GladeSharper. As a Glade file, you select in your Project folder and as a C# file you select GladeAppDummy.cs -- i.e. the file from above -- in the same folder. Click "Start watcher." Now you can start Glade and open in your Project folder again. Design your GUI and save it. Then the widgets and signals are made available in your Editor. You just have to reload the code when VS asks you. Don't forget to uncomment window1.Show() after you've created the first window.

To make the application react on the Close button, you create the signal destroy for your window. Save the Glade file. The signal will be added to your code. Then put in Application.Quit(), as shown below:

voidon_window1_destroy(object sender, EventArgse)


The widgets are placed in #region GtkWidgetDeclarations. Don't write any code within this section, as it will be deleted. However, you can move the whole region and it will stay there when the code is updated. You can move the signal handlers freely in your code wherever you like; they will not be moved again or deleted. They also won't get deleted when you deactivate the signal in Glade! So, if a signal is no longer responding, have a look at Glade's properties!

To find out which EventArgs a signal uses, I had to use Reflection. In the Glade file is the name of the widget and the signal. With Reflection, I look up the signal and find out which EventArgs it uses. You will have something like this:

voidon_window1_client_event(object sender, Gtk.ClientEventArgse)

voidon_togglebutton1_toggled(object sender, System.EventArgse)

As you can see, the EventArgs have full qualifiers like System.EventArgs. Sometimes the name of the signal cannot be found in the Gtk# API. In this case, the signal will also be put in the code and it will be functional. It could be, however, that it has special EventArgs. You will recognize this through seeing that EventArgs is not qualified, i.e. there is no preceeding System.

voidon_button1_activate(object sender, EventArgse)

That is the one example I spoke of. The Event here is called Activate, but in the Gtk# API it is called Activated. Either way, the EventArgs of Button.Activated are System.EventArgs so it makes no diference. When you see a signal handler with unqualified EventArgs, you know that GladeSharper was not able to find it in the API. If you look by hand, it may be that the signal has more special EventArgs.


A last hint: If you are unsure about whether you saved your code, when the Editor tells you that the code has changed and asks if you want to reload it, just click No. Save your code and click Save in Glade again. I hope you like the generator! If you are missing functions, post in detail in the comments section!


  • 18 July, 2007 -- Original version posted


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Marek Wyborski

Germany Germany
No Biography provided

Comments and Discussions

GeneralLittle bug but great features! PinmemberMember 167849518-Aug-08 3:30 
your application is very handy, even just for an initial build of a skeleton.
But I found a misbehaviour when saving the .glade-file the second time.
Somehow the application crashes with some weird address violation error.
Tried this using Windows Xp.
GeneralVery interesting Pinmembergerektoolhy18-Jul-07 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 18 Jul 2007
Article Copyright 2007 by Marek Wyborski
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid