|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
What is GTK#?This question maybe better answered by the GTK# site or the GTK# page on Mono's website. Simply, it's a wrapper on The Gimp Toolkit, or GTK+, a cross platform GUI framework that got its fame for the GIMP image editor and the foundation of Gnome desktop popular on Linux and FreeBSD desktops. Currently, it works natively for any X server, Direct Framebuffer system, or even using the native Windows UI. That means, it works on pretty much everything but will look the best on Linux, great on Windows, and be functional on MacOSX (it may look out of place with the Aqua look which is the biggest issue I've seen). GTK+ has been around for years, so it's very complete, heavily tested, and already come preinstalled on almost all desktop Linux machines. One big misconception is that GTK# requires Mono to work. This is far from true. All that GTK# needs is a .NET compatible runtime. Currently, the only runtimes I know of are MS.NET, Mono, and DotGNU. GTK# is regularly tested on MS.NET, DotGNU, and Mono. This means if you write your applications in GTK# and decide you wish to run on Windows as well, you can choose to deploy with just GTK# and use Microsoft's runtime, or deploy with Mono's runtime for Windows and deploy that way as well. Download/Install GTK#First thing you will want to do is get your GTK# install up and running. Linux, MacOSX, FreeBSD, and others:See if your distribution has GTK# devel packages as well as any Mono packages first. If not, check out Downloads to find a package that works for you. In the worst case, you may be forced to build yourself from source. Windows:If you are on Windows, pick yourself up a copy of the integrated installer from that download page. You also can grab a copy of the GTK# integration package for Visual Studio which will allow you to use GTK# without Mono. I'm going to use GTK# 2.0 (v1.9.3 as of this writing) which is based on GTK+ 2.4. You may choose to use GTK# 1.0 (based on GTK+ 2.2) and most of what I'm going to go over should still apply. I highly recommend using GTK# 2.0. Inside the GTK# librariesGTK# is made up of several packages.
There are other libraries that we commonly associate as being part of the GTK# framework, pr., Gecko#, Gtksourceview#, GSF#, Guile#, and GST# which are not packaged with the GTK# releases but in most parts part of the same bout. They are very useful for doing the specific things they provide but we won't touch on them too much here. Step 1 - Get readyThe first part we need to do is create a new folder for our little project. (Windows users: let's avoid spaces in the folder name just to take out any headaches.) You will then want to open a shell (if you are on Windows, open the Start menu and go to "Programs->Mono 1.x.x->Mono Command Prompt" and will set up your paths so you don't have to do anything extra). You will want to cd to that directory we just created. We are going to be using this window a lot so leave it running in the background. Now go ahead, open up your favorite editor (MonoDevelop, vi, Emacs, Notepad, etc.) and setup a new blank project (if applicable) and create a new blank file. Go ahead and save this file as "helloworld.cs". Step 2 - Laying it outI'm assuming that you are familiar with C# so most of this will look normal. We will need to create a new reference to GTK#, and create a new class and entry point for our application. It should look something like this: using System;
using Gtk;
public class GtkHelloWorld {
public static void Main() {
Console.WriteLine("HelloWorld");
}
}
That should look pretty familiar to you. Just so we can get used to using the command compiler, let's go ahead and save this. Then switch back to our shell window and go ahead and run: mcs -pkg:gtk-sharp-2.0 helloword.cs
Some of you that have used the CSC compiler on Windows may notice the "-pkg:" as a little odd. This doesn't exist in CSC because Mono comes from the world of Linux. What that does is lookup for a package config file under that name. In the package config folder exists a file named gtk-sharp-2.0.pc which contains (among other information) the location of the libraries for that package. That way we don't have to type out "-r:gtk-sharp-2.0.dll -r:atk-sharp-2.0.dll -r:pango-sharp-2.0.dll ...." all by hand. Step 3 - The fun partNow, let's jump back to our code. Go ahead and remove the using System;
using Gtk;
public class GtkHelloWorld {
public static void Main() {
Application.Init();
//Create the Window
Window myWin = new Window("My first GTK# Application! ");
myWin.Resize(200,200);
//Create a label and put some text in it.
Label myLabel = new Label();
myLabel.Text = "Hello World!!!!";
//Add the label to the form
myWin.Add(myLabel);
//Show Everything
myWin.ShowAll();
Application.Run();
}
}
Now just compile like we did before and run it using 'mono HelloWorld.exe' and you should get something like this:
The first thing that you might notice, if you have used Now you maybe asking yourself, "How do you then add more then one widget to a window if it can only contain one widget?" Well, we have other widgets that have the ability to contain multiple widgets at the same time. Some of those widgets will inherit from a In order to have multiple widgets on our The other part you may be interested in is what the It really doesn't get any easier than that. If you are used to Points of Interest
|
||||||||||||||||||||||