Hello,

First, this is being cross posted to both the Gtk# Mailing List and the Mono Docs Mailing List.  So make sure to do a "Reply to All" when replying to this.  (So that everyone can keep up with the conversation.)

I recommend that this tutorial come right after the GNOME.NET Hello World tutorial.  (It is being written with that expectation.  Also, IMO, it is a good next step for the reader to take.)

(Some one else, with the ability, will again need to add this to the MonkeyGuide.)


Here's the tutorial.

------- BEGIN -------

GNOME.NET

In the previous GNOME.NET tutorial, we learnt how to make a GNOME application window.  However, other than being a good example to teach us GNOME.NET,  that window was pretty useless, considering it didn't really do anything.

Any real application will have stuff inside the window.  In this tutorial, we will show you how to give your window some contents.

Adding Contents

button.cs:

    class MainClass
    {
            static void Main(string[] args)
            {
                    Gnome.Program program =
                    new Gnome.Program("Hello World", "1.0", Gnome.Modules.UI, args);

                    MyMainWindow app = new MyMainWindow(program);
                    app.Show();
 
                    program.Run();
            }
    }



    class MyMainWindow
            : Gnome.App
    {
            Gnome.Program program;

            public MyMainWindow(Gnome.Program gnome_program)
                    : base("Hello World", "Hello World")
            {
                    this.program = gnome_program;

                    this.DeleteEvent += new GtkSharp.DeleteEventHandler(delete_event);

                    this.Contents = new Gtk.Button("Hello World");
            }

            private void delete_event(object obj, GtkSharp.DeleteEventArgs args)
            {
                    this.program.Quit();
            }
    }


compile:

mcs button.cs -r gnome-sharp.dll


run:

mono button.exe


Except for one line, this code is virtually exactly like the helloworld2.cs source code from the previous tutorial.  The line that adds the button is:

                    this.Contents = new Gtk.Button("Hello World");


The magic comes from the Contents property of Gnome.App (and all of Gnome.App's subclasses, like MyMainWindow).

What you assign to this goes inside the window.  For example, I could put an image in there with:

                    Gtk.Image image = new Gtk.Image();

                    // put something in the image here.

                    this.Contents = image;


I could put in a Gnome.Canvas with.

                    this.Contents = new Gnome.Canvase();


(Hopefully you get the idea.)  If you want to put something inside of a Gnome.App (or one of its subclasses), then assign it to its Contents property.

-------- END --------



See ya

-- 
     Charles Iliya Krempeaux, BSc
     [EMAIL PROTECTED]

________________________________________________________________________
 Reptile Consulting & Services    604-REPTILE    http://www.reptile.ca/

Reply via email to