advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the Code for this Article
Partners & Affiliates
advertisement
advertisement
Rate this item | 0 users have rated this item.
 Print Print
 
Building Robust UIs in Mono with Gtk#
Learn to use the native Gtk# GUI toolkit to build Mono-based desktop applications today. 

advertisement
ust 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.

  Next Page: Building a Main Window


Page 1: IntroductionPage 4: Understanding Gtk# Layout Managers
Page 2: Building a Main WindowPage 5: Displaying Dialog Boxes
Page 3: The World of Widgets 
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


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
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
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
HP Video: StorageWorks EVA4400 and Oracle
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
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES