Before that you need to install these packages :
glade-gnome
libglade2.0-cil
mono-mcs
libgtk2.0-cil
And also your favorite text editor or IDE.
Create a new file GladeApp.cs with the source-code below.
using System;
using Gtk;
using Glade;
public class GladeApp
{
// declare the widgets you will use from glade
[Glade.WidgetAttribute]
Gtk.Entry MyEntry;
public static void Main (string[] args)
{
new GladeApp (args);
}
public GladeApp (string[] args)
{
Application.Init();
Glade.XML gxml = new Glade.XML ("gui.glade", "MyWindow", null);
gxml.Autoconnect (this);
Application.Run();
}
// Connect the Signals defined in Glade
public void OnMyWindowDeleteEvent (object o, DeleteEventArgs args)
{
Application.Quit ();
args.RetVal = true;
}
public void OnMyButtonClicked(object o, EventArgs args)
{
Console.WriteLine("In entry: " + MyEntry.Text);
}
}
Then, start your Glade.
Build a simple window with a text entry and a button. It will be looked like this :

With additional event & signal. delete_event event for MyWindow

and clicked signal for MyButton.

Saved the glade file as gui.glade . You may need to learn a little bit to create these user-interface. Please keep trying.
Then you are ready to compile our code.
myprompt: mcs -pkg:gtk-sharp-2.0 -pkg:glade-sharp-2.0 GladeApp.cs
And run our application.
myprompt: mono GladeApp.exe

Congratulation...
No comments:
Post a Comment