[Mono-devel-list] Mono on Windows HOWTO

Brian Rose lists at brianrose.net
Wed Oct 20 13:24:27 EDT 2004


I went to the documentation page to find some information on how to use 
Mono on my WindowsXP system. This is what I found...

   Mono Handbook
   Mono on Windows: Getting started

   To install Mono, get the Windows installer for Mono from
   http://www.mono-project.com/downloads/ and run it.

   (TODO: this needs to be filled in more by someone who uses
   Mono on Windows.)

So it looks like I unwittingly volunteered for the Windows documentation job!

Anyway, I downloaded the installer and followed the instructions. I was 
able to get a basic console "Hello World" app running. Now I'd like to make 
a form-based program to create a simple Windows GUI program.

I created the source program (listed below) because it seemed simple enough 
(not too many GUI "Hello World" apps out there). It is based on GTH#, which 
I understand is installed with the Windows installer. When I compile it I 
get the following error...

   Mono version 1.0.1 Build 1
   Prepending 'C:\PROGRA~1\MONO-1~1.2\bin' to PATH

   C:\cygwin\home\brose\bmp2disp>mcs gui.cs
   gui.cs(20) error CS0246: Cannot find type `DeleteEventArgs'
   gui.cs(4) error CS0246: The namespace `Gtk' can not be found (missing
   assembly reference?)
     Try using -r:gtk-sharp
   gui.cs(5) error CS0246: The namespace `GtkSharp' can not be found
   (missing assembly reference?)
     Try using -r:gtk-sharp
   gui.cs(7) error CS0246: The namespace `System.Drawing' can not be found
     (missing assembly reference?)
     Try using -r:System.Drawing
   Compilation failed: 4 error(s), 0 warnings

So I try it with the references...

   C:\cygwin\home\brose\bmp2disp>mcs -r:gtk-sharp -r:System.Drawing gui.cs
   error CS0006: Cannot find assembly `gtk-sharp'
   Log:

   Compilation failed: 1 error(s), 0 warnings

So how do I find the gtk-sharp assembly or see what assemblies are installed?


======================================================================
// helloworld.cs - Gtk# Tutorial example

using Gtk;
using GtkSharp;
using System;
using System.Drawing;


public class helloworld {

/* This is a callback function. The data arguments are ignored
  * in this example. More on callbacks below. */
static void hello (object obj, EventArgs args)
{
	Console.WriteLine("Hello World");
	Application.Quit ();
}

static void delete_event (object obj, DeleteEventArgs args)
{
	/* If you return FALSE in the "delete_event" signal handler,
	 * GTK will emit the "destroy" signal. Returning TRUE means
	 * you don't want the window to be destroyed.
	 * This is useful for popping up 'are you sure you want to quit?'
	 * type dialogs. */
     Console.WriteLine ("delete event occurred\n");
     Application.Quit ();
}

public static void Main(string[] args)
{
	/* This is called in all GTK applications. Arguments are parsed
	 * from the command line and are returned to the application. */
	Application.Init ();

	/* create a new window */
	Window window = new Window ("helloworld");
	/* When the window is given the "delete_event" signal (this is
	 * given by the window manager, usually by the "close" option, or
	 * on the titlebar), we ask it to call the delete_event ()
	 * function as defined above. The data passed to the callback
	 * function is NULL and is ignored in the callback function. */

	window.DeleteEvent += new DeleteEventHandler (delete_event);

	/* Sets the border width of the window. */
	window.BorderWidth = 10;
	/*  gtk_container_set_border_width (GTK_CONTAINER (window), 10);*/

	/* Creates a new button with the label "Hello World". */
	Button btn = new Button ("Hello World");

	/* When the button receives the "clicked" signal, it will call the
	 * function hello() passing it NULL as its argument.  The hello()
	 * function is defined above. */
	btn.Clicked += new EventHandler (hello);


	/* This packs the button into the window (a gtk container). */
	window.Add (btn);

	/* The final step is to display this newly created widget. */
	window.ShowAll ();


	/* All GTK applications must have a gtk_main(). Control ends here
	* and waits for an event to occur (like a key press or
	* mouse event).
	* In C#, we use Application.Run(), as used in Windows.Forms*/

	Application.Run ();

}
}
======================================================================

--

Brian











More information about the Mono-devel-list mailing list