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.
Delegates
Delegates are an elegant means to do old school C-style function pointers. Like function pointers, the actual implementation isn't discovered until run-time. The only thing that the delegate knows is the signature of the function. In the example about, C# doesn't care what happens or doesn't happen in the body of the function. It only matters that the signature matches what is expected.
On the homestretch
We need to be able to access our label to change the text when the button is clicked. We expose widgets from the layout with the [Widget] attribute just in front of the widget's declaration.
[Widget] Label label1;
The name must match the one in Glade. Not having to expose the widgets is the main advantage of using Autoconnect. Without it, we would have to expose the window, the button, and the two menus items. For the About menu item event handler, I chose to make the dialog by hand to give you a real feel for how much time you are saving by using Glade. Happy coding!
To compile :
mcs HelloWorld.cs -pkg:gtk-sharp -pkg:glade-sharp -resource:gui.glade
Click Here To View A Screenshot
Mono : http://www.go-mono.org