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.)
This is my third draft of the GNOME.NET HelloWorld tutorial, for the MonkeyGuide.
The first draft has already been posted in the MonekyGuide, and can be found at:
http://go-mono.com/tutorial/html/en/gnome/bindings/gnome/hello_world.html
(It actually got posted by 2 at least different people.)
The second draft was never committed (as far as I know).
This third draft basically incorporates the latest suggestions. It also contains some additions and corrections.
(Some one else, with the ability, will again need to add this to the MonkeyGuide.)
Here's the first tutorial, GNOME.NET Hello World:
------- BEGIN -------
GNOME.NET
This tutorial gets you started with writing GNOME.NET programs.HelloWorld, first try
helloworld1.cs:
|
compile:
|
run:
|
It's a bit longer than console Hello World and needs some explanation.
In Main() at first you see:
|
This initializes GNOME and is needed in every GNOME application. Here we are creating a variable of type Gnome.Program, called program. This variable, program, is used to control the GNOME program, as we'll see later.
Next we see:
|
This creates our GNOME application window. (That's what you see on the screen.)
We then see:
|
This makes the GNOME Application Window (that you created with the previous line of code) visible on the screen. With GNOME, things don't automatically display themselves unless you explicitly tell them too.
And finally we see:
|
This make your GNOME program run. It makes all the magic happen, that you don't need to worry about at this moment. Needless to say though, you need to do this to make your GNOME Application work.
HelloWorld, second try
While the above program compiles and runs, it's doesn't quit, properly. You have to exit by pressing CTRL+C. (Ideally, we want the program to close when you press the "X" on the title bar. Which is what this next example does.)helloworld2.cs:
|
compile:
|
run:
|
The first thing you probably have noticed is that there are now two classes. The first class -- HelloWorld -- is almost identical to the version in the previous example. Except for the following line:
|
You can compare this to the equivalent line in the previous code:
|
The difference is that app is no longer an instance of Gnome.App, as it was in the first example helloworld.cs. But is now an instance of a new class that we just created: MyMainWindow. (Also, what we pass to the constructor of MyMainWindow is different from what we passed to the constructor of Gnome.App.)
In other words, the only difference (in this class) is that we are using a different class for our window.
Now let us take a look at our MyMainWindow class.
We created this new class because Gnome.App did not do exactly what we wanted it to. We want our application window to close when the "X" on the title bar is pressed. Which is what the code in the MyMainWindow class accomplishes.
The important thing to focus on is this line:
|
This makes it so that when the "X" button on the title bar is pressed, the function delete_event is called. Technically, when the "X" button is pressed, the program receives a DeleteEvent, which is what you see in the code above.
The next thing to focus on is the definition of delete_event:
|
This is the function that is called when the application receives a DeleteEvent. I.e., when the user clicks the "X" button on the title bar. As you can hopefully see, when this function is called, the program will quit.
Which is what we wanted.
-------- END --------
See ya
--
Charles Iliya Krempeaux, BSc
[EMAIL PROTECTED]
________________________________________________________________________
Reptile Consulting & Services 604-REPTILE http://www.reptile.ca/
|
