APIFinder
   The essential directory of application programming interfaces
Submit an API
DevX
Function
Language/OS
Contribute
About
Browse DevX
advertisement
Log In | Register
Building Robust UIs in Mono with Gtk#
Learn to use the native Gtk# GUI toolkit to build Mono-based desktop applications today. 
March 4, 2008

advertisement
Just as Microsoft provides a native desktop UI toolkit called Windows Forms that ships with Microsoft .NET, the Mono project provides a compatible implementation of this same API, making it possible to build Windows Forms-based applications that run under a variety of operating systems.

Author's Note: When this article was written, Mono's implementation of Windows Forms had not yet been finalized (see this blog to view the current status of the project).

Even though Mono's Windows Forms implementation is not yet feature-complete you can use Mono to build robust desktop applications today by choosing an alternative API (see Table 1).

Table 1. A Survey of .NET desktop APIs: The table shows some of the APIs available for building desktop applications with Mono.
.NET Desktop
GUI API
Description
Gtk# Gtk# is considered the "native" GUI toolkit that ships with the Mono platform.
Glade# Glade# is an extension to Gtk#. Beyond adding several useful widgets, GUIs built using Glade# can be described via XML and bound to a runtime object model.
Cocoa# Cocoa# is a managed wrapper around the native Mac OS X cocoa API.
wx.NET Wx.NET is a wrapper around the platform-independent wx toolkit. A (major) benefit of Wx.NET is that it maintains the correct look-and-feel of the host OS (including Mac OS X).

This article introduces you to a very popular .NET GUI alternative named Gtk#. As you would expect from a modern-day desktop API, Gtk# provides a very rich fabric for building desktop applications. I'll discuss the following core topics:

  • Building main windows
  • Working with widgets
  • Creating menu systems
  • Understanding the role of HBox and VBox types
  • Creating and using dialog boxes
Author's Note: This article assumes that you're comfortable with C# and working with the .NET type system (classes, interfaces, enumerations, structures and delegates).

Getting to Know Gtk#
Gtk# is a managed wrapper around a Linux-centric API termed Gtk+. Gtk+ is a toolkit originally created to build the popular image processing application GIMP (the GNU Image Manipulation Program), which explains the origin of the acronym 'Gtk': GIMP Tool Kit.

Although Gtk+ was originally developed for use on Unix/Linux, this API has been ported to numerous operating systems (Win32, Mac OX X, etc). Given the connection between Gtk# and Gtk+, it should come as no surprise that you can use Gtk# to build platform-independent user interfaces on any operating system that supports Gtk+.

Structurally, Gtk# consists of a set of .NET assemblies deployed to the Mono Global Assembly Cache. Table 2 defines the role of the core Gtk# assemblies.

Table 2. The Core Gtk# Assemblies: The table lists the most important Gtk# assemblies and a description of each.
Gtk# Assembly Description
gtk-sharp.dll Defines the core UI .NET bindings to Gtk+.
glib-sharp.dll Defines additional (non-UI) .NET bindings to Gtk+.
pango-sharp.dll Provides binding to the Pango API, used to format and internationalize textual data.
atk-sharp.dll Binding for the atk accessibility API.
gdk-sharp.dll Defines numerous low-level rendering APIs.
glade-sharp.dll Provides support for Glade development with Gtk#.
art-sharp.dll A vector rending library.
rsvg-sharp.dll A SVG rendering library.

Figure 1: The MonoDoc UI: MonoDoc Provides Solid Documentation for Gtk#.

The Mono installation automatically deploys the Gtk# assemblies to the Mono GAC when you install the Mono platform on a Windows or Linux-based OS. Do be aware that installing Gtk# on Mac OS X is a bit more involved. Interested individuals can find OS X installation instructions here.

While this article will in no way attempt to dive into the details of every type found within each Gtk# assembly, you'll find the API is well documented in the MonoDoc utility (see Figure 1).

A Survey of Gtk# Development Options
In this article you'll see how to build several Gtk# applications at the command line using the Mono C# compiler (gmcs) and your text editor of choice. I realize that this is not the visual GUI-building process you may be used to in Visual Studio, but bear with me—this approach is ideal from a learning point of view. Rest assured that if you are serious about building Gtk# user interfaces, several Mono-aware IDEs provide design time assistance. Table 3 documents several possibilities.

Author's Note: See Mono IDEs: Going Beyond the Command Line for more information on these Mono-aware IDEs.

Table 3. Mono-Aware IDEs: The table lists several IDEs that offer visual design support for Gtk# development.
.NET Desktop UI Technology Description
#develop SharpDevelop 2.0 provides Gtk# and Glade# project templates, however it currently lacks visual designer support.
MonoDevelop Provides a variety of visual tools for building Gtk# / Glade# projects.
X-Develop Provides a variety of visual tools for building Gtk# / Glade# projects.

In addition to the IDEs in Table 3, it is possible to build Gtk# applications using Visual Studio 2005 (as well as earlier editions of the product). Check out the following blog for more information.

Continue reading the article on DevX.com...

Andrew Troelsen enjoys his life working within the .NET universe. He has authored several best selling books (and numerous articles) on the topics of the .NET platform and the C# / VB programming languages. He works as a corporate trainer and consultant for Intertech Training.


GtkSharp
Gtk#, a GUI Toolkit, is a set of .NET bindings for the gtk+ toolkit and assorted GNOME libraries. This library allows you to build fully native graphical Gnome applications using Mono. GTK# is an event-driven system like any other modern windowing library. Every widget in an application has handler methods that get called when particular events happen.
Provider: Mono   Cost: 0




JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Microsoft Article: 7.0, Microsoft's Lucky Version?
Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Windows Server 2008
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES