[Mono-docs-list] MonkeyGuide?: GNOME.NET Adding Contents Tutorial - First Draft

Charles Iliya Krempeaux charles@reptile.ca
19 Feb 2003 22:37:47 -0800


--=-UHfZmrq7lLDIb4JwRVDx
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

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
     charles@reptile.ca

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

--=-UHfZmrq7lLDIb4JwRVDx
Content-Type: text/html; charset=utf-8

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/1.1.8">
</HEAD>
<BODY>
Hello,<BR>
<BR>
First, this is being cross posted to both the Gtk# Mailing List and the Mono Docs Mailing List.&nbsp; So make sure to do a &quot;Reply to All&quot; when replying to this.&nbsp; (So that everyone can keep up with the conversation.)<BR>
<BR>
I recommend that this tutorial come right after the GNOME.NET Hello World tutorial.&nbsp; (It is being written with that expectation.&nbsp; Also, IMO, it is a good next step for the reader to take.)<BR>
<BR>
(Some one else, with the ability, will again need to add this to the MonkeyGuide.)<BR>
<BR>
<BR>
Here's the tutorial.<BR>
<BR>
<FONT SIZE="3"><TT>------- BEGIN -------</TT></FONT><BR>
<BR>
<H1>GNOME.NET</H1>
In the previous GNOME.NET tutorial, we learnt how to make a GNOME application window.&nbsp; However, other than being a good example to teach us GNOME.NET,&nbsp; that window was pretty useless, considering it didn't really do anything.<BR>
<BR>
Any real application will have <I>stuff</I> inside the window.&nbsp; In this tutorial, we will show you how to give your window some contents.
<H2>Adding Contents</H2>
<FONT SIZE="3"><TT>button.cs</TT></FONT>:<BR>
<BR>
<TABLE BGCOLOR="#bfbfbf" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<TABLE BGCOLOR="#f2f2f2" CELLSPACING="1" CELLPADDING="3" WIDTH="100%">
<TR>
<TD BGCOLOR="#d5d5d5">
<FONT SIZE="3"><TT>&nbsp;&nbsp;&nbsp; class MainClass<BR>
&nbsp;&nbsp;&nbsp; {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Main(string[] args)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gnome.Program program =<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Gnome.Program(&quot;Hello World&quot;, &quot;1.0&quot;, Gnome.Modules.UI, args);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyMainWindow app = new MyMainWindow(program);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; app.Show();<BR>
&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; program.Run();<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp; }<BR>
<BR>
<BR>
<BR>
&nbsp;&nbsp;&nbsp; class MyMainWindow<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Gnome.App<BR>
&nbsp;&nbsp;&nbsp; {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gnome.Program program;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public MyMainWindow(Gnome.Program gnome_program)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : base(&quot;Hello World&quot;, &quot;Hello World&quot;)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.program = gnome_program;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DeleteEvent += new GtkSharp.DeleteEventHandler(delete_event);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Contents = new Gtk.Button(&quot;Hello World&quot;);<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void delete_event(object obj, GtkSharp.DeleteEventArgs args)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.program.Quit();<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>
&nbsp;&nbsp;&nbsp; }</TT></FONT>
</TD>
</TR>
</TABLE>

</TD>
</TR>
</TABLE>
<BR>
<BR>
compile:<BR>
<BR>
<TABLE BGCOLOR="#bfbfbf" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<TABLE BGCOLOR="#f2f2f2" CELLSPACING="1" CELLPADDING="3" WIDTH="100%">
<TR>
<TD BGCOLOR="#808080">
<FONT COLOR="#ffffff" SIZE="3"><TT>mcs button.cs -r gnome-sharp.dll</TT></FONT>
</TD>
</TR>
</TABLE>

</TD>
</TR>
</TABLE>
<BR>
<BR>
run:<BR>
<BR>
<TABLE BGCOLOR="#bfbfbf" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<TABLE BGCOLOR="#f2f2f2" CELLSPACING="1" CELLPADDING="3" WIDTH="100%">
<TR>
<TD BGCOLOR="#808080">
<FONT COLOR="#ffffff" SIZE="3"><TT>mono button.exe</TT></FONT>
</TD>
</TR>
</TABLE>

</TD>
</TR>
</TABLE>
<BR>
<BR>
Except for one line, this code is virtually exactly like the <TT>helloworld2.cs</TT> source code from the previous tutorial.&nbsp; The line that adds the button is:<BR>
<BR>
<TABLE BGCOLOR="#bfbfbf" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<TABLE BGCOLOR="#f2f2f2" CELLSPACING="1" CELLPADDING="3" WIDTH="100%">
<TR>
<TD BGCOLOR="#d5d5d5">
<FONT SIZE="3"><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Contents = new Gtk.Button(&quot;Hello World&quot;);</TT></FONT>
</TD>
</TR>
</TABLE>

</TD>
</TR>
</TABLE>
<BR>
<BR>
The magic comes from the <TT>Contents</TT> property of <TT>Gnome.App</TT> (and all of <TT>Gnome.App</TT>'s subclasses, like MyMainWindow).<BR>
<BR>
What you assign to this goes inside the window.&nbsp; For example, I could put an image in there with:<BR>
<BR>
<TABLE BGCOLOR="#bfbfbf" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<TABLE BGCOLOR="#f2f2f2" CELLSPACING="1" CELLPADDING="3" WIDTH="100%">
<TR>
<TD BGCOLOR="#d5d5d5">
<FONT SIZE="3"><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Gtk.Image image = new Gtk.Image();<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // put something in the image here.<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Contents = image;</TT></FONT>
</TD>
</TR>
</TABLE>

</TD>
</TR>
</TABLE>
<BR>
<BR>
I could put in a <TT>Gnome.Canvas</TT> with.<BR>
<BR>
<TABLE BGCOLOR="#bfbfbf" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<TABLE BGCOLOR="#f2f2f2" CELLSPACING="1" CELLPADDING="3" WIDTH="100%">
<TR>
<TD BGCOLOR="#d5d5d5">
<FONT SIZE="3"><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Contents = new Gnome.Canvase();</TT></FONT>
</TD>
</TR>
</TABLE>

</TD>
</TR>
</TABLE>
<BR>
<BR>
(Hopefully you get the idea.)&nbsp; If you want to put something inside of a <TT>Gnome.App</TT> (or one of its subclasses), then assign it to its <TT>Contents</TT> property.<BR>
<BR>
<FONT SIZE="3"><TT>-------- END --------</TT></FONT><BR>
<BR>
<BR>
<BR>
See ya<BR>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<PRE>-- 
     Charles Iliya Krempeaux, BSc
     charles@reptile.ca

________________________________________________________________________
 Reptile Consulting &amp; Services    604-REPTILE    http://www.reptile.ca/</PRE>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>

--=-UHfZmrq7lLDIb4JwRVDx--