mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-01-11 21:35:39 +00:00
add tutorial files
svn path=/trunk/gtk-sharp/; revision=8836
This commit is contained in:
parent
36d289986c
commit
ed9f671d84
11
sample/tutorial/arrow/Makefile
Normal file
11
sample/tutorial/arrow/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
CSC = mcs
|
||||
|
||||
DLLS = -r glib-sharp.dll \
|
||||
-r gtk-sharp.dll \
|
||||
-r System.Drawing.dll
|
||||
|
||||
all:
|
||||
$(CSC) /unsafe $(DLLS) arrow.cs
|
||||
clean:
|
||||
rm -f *.exe
|
85
sample/tutorial/arrow/arrow.cs
Normal file
85
sample/tutorial/arrow/arrow.cs
Normal file
|
@ -0,0 +1,85 @@
|
|||
// arrow.cs - Gtk# Tutorial example
|
||||
//
|
||||
// Author: Johannes Roith <johannes@jroith.de>
|
||||
//
|
||||
// (c) 2002 Johannes Roith
|
||||
|
||||
namespace GtkSharpTutorial {
|
||||
|
||||
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
|
||||
public class arrow
|
||||
{
|
||||
|
||||
static void delete_event (object obj, DeleteEventArgs args)
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
/* Create an Arrow widget with the specified parameters
|
||||
* and pack it into a button */
|
||||
|
||||
static Widget create_arrow_button(ArrowType arrow_type, ShadowType shadow_type )
|
||||
{
|
||||
|
||||
Button button = new Button ();
|
||||
Arrow arrow = new Arrow (arrow_type, shadow_type);
|
||||
|
||||
button.Add(arrow);
|
||||
|
||||
button.Show();
|
||||
arrow.Show();
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
/* Initialize the toolkit */
|
||||
Application.Init ();
|
||||
|
||||
/* Create a new window */
|
||||
Window window = new Window ("Arrow Buttons");
|
||||
|
||||
/* It's a good idea to do this for all windows. */
|
||||
|
||||
window.DeleteEvent += new DeleteEventHandler (delete_event);
|
||||
|
||||
/* Sets the border width of the window. */
|
||||
window.BorderWidth = 10;
|
||||
|
||||
/* Create a box to hold the arrows/buttons */
|
||||
HBox box = new HBox (false, 0);
|
||||
box.BorderWidth = 2;
|
||||
window.Add(box);
|
||||
|
||||
/* Pack and show all our widgets */
|
||||
box.Show();
|
||||
|
||||
Widget button1 = create_arrow_button(ArrowType.Up, ShadowType.In);
|
||||
box.PackStart (button1, false, false, 3);
|
||||
|
||||
Widget button2 = create_arrow_button(ArrowType.Down, ShadowType.Out);
|
||||
box.PackStart (button2, false, false, 3);
|
||||
|
||||
Widget button3 = create_arrow_button(ArrowType.Left, ShadowType.EtchedIn);
|
||||
box.PackStart (button3, false, false, 3);
|
||||
|
||||
Widget button4 = create_arrow_button(ArrowType.Right, ShadowType.EtchedOut);
|
||||
box.PackStart (button4, false, false, 3);
|
||||
|
||||
|
||||
window.ShowAll ();
|
||||
|
||||
/* Rest in Application.Run() and wait for the fun to begin! */
|
||||
Application.Run();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
sample/tutorial/aspectframe/Makefile
Normal file
11
sample/tutorial/aspectframe/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
CSC = mcs
|
||||
|
||||
DLLS = -r glib-sharp.dll \
|
||||
-r gtk-sharp.dll \
|
||||
-r System.Drawing.dll
|
||||
|
||||
all:
|
||||
$(CSC) /unsafe $(DLLS) aspectframe.cs
|
||||
clean:
|
||||
rm -f *.exe
|
57
sample/tutorial/aspectframe/aspectframe.cs
Normal file
57
sample/tutorial/aspectframe/aspectframe.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
// aspectframe.cs - Gtk# Tutorial example
|
||||
//
|
||||
// Author: Johannes Roith <johannes@jroith.de>
|
||||
//
|
||||
// (c) 2002 Johannes Roith
|
||||
|
||||
namespace GtkSharpTutorial {
|
||||
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
|
||||
public class aspectframe
|
||||
{
|
||||
|
||||
static void delete_event (object obj, DeleteEventArgs args)
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
Application.Init ();
|
||||
|
||||
/* Create new window */
|
||||
Window window = new Window ("Aspect Frame");
|
||||
window.BorderWidth = 10;
|
||||
|
||||
window.DeleteEvent += new DeleteEventHandler (delete_event);
|
||||
|
||||
/* Create an aspect_frame and add it to our toplevel window */
|
||||
|
||||
AspectFrame aspect_frame = new AspectFrame("2x1", (float)0.5,(float)0.5, 2, false);
|
||||
|
||||
window.Add(aspect_frame);
|
||||
aspect_frame.Show();
|
||||
|
||||
/* Now add a child widget to the aspect frame */
|
||||
|
||||
DrawingArea drawing_area = new DrawingArea();
|
||||
|
||||
/* Ask for a 200x200 window, but the AspectFrame will give us a 200x100
|
||||
* window since we are forcing a 2x1 aspect ratio */
|
||||
drawing_area.SetSizeRequest (200, 200);
|
||||
aspect_frame.Add(drawing_area);
|
||||
drawing_area.Show();
|
||||
|
||||
window.ShowAll();
|
||||
|
||||
Application.Run();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
sample/tutorial/base/Makefile
Normal file
11
sample/tutorial/base/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
CSC = mcs
|
||||
|
||||
DLLS = -r glib-sharp.dll \
|
||||
-r gtk-sharp.dll \
|
||||
-r System.Drawing.dll
|
||||
|
||||
all:
|
||||
$(CSC) /unsafe $(DLLS) base.cs
|
||||
clean:
|
||||
rm -f *.exe
|
31
sample/tutorial/base/base.cs
Normal file
31
sample/tutorial/base/base.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
// base.cs - Gtk# Tutorial example
|
||||
//
|
||||
// Author: Johannes Roith <johannes@jroith.de>
|
||||
//
|
||||
// (c) 2002 Johannes Roith
|
||||
|
||||
namespace GtkSharpTutorial {
|
||||
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
using System;
|
||||
|
||||
|
||||
public class baseclass {
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
Application.Init ();
|
||||
|
||||
Window window = new Window ("base");
|
||||
window.Show();
|
||||
|
||||
Application.Run ();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
sample/tutorial/buttons/Makefile
Normal file
11
sample/tutorial/buttons/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
CSC = mcs
|
||||
|
||||
DLLS = -r glib-sharp.dll \
|
||||
-r gtk-sharp.dll \
|
||||
-r System.Drawing.dll
|
||||
|
||||
all:
|
||||
$(CSC) /unsafe $(DLLS) buttons.cs
|
||||
clean:
|
||||
rm -f *.exe
|
96
sample/tutorial/buttons/buttons.cs
Normal file
96
sample/tutorial/buttons/buttons.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
// buttons.cs - Gtk# Tutorial example
|
||||
//
|
||||
// Author: Johannes Roith <johannes@jroith.de>
|
||||
//
|
||||
// (c) 2002 Johannes Roith
|
||||
|
||||
namespace GtkSharpTutorial {
|
||||
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
|
||||
public class buttons
|
||||
{
|
||||
|
||||
/* Create a new hbox with an image and a label packed into it
|
||||
* and return the box. */
|
||||
|
||||
static Widget xpm_label_box(string xpm_filename, string label_text )
|
||||
{
|
||||
|
||||
|
||||
/* Create box for image and label */
|
||||
HBox box = new HBox(false, 0);
|
||||
box.BorderWidth = 2;
|
||||
|
||||
/* Now on to the image stuff */
|
||||
Gtk.Image image = new Gtk.Image(xpm_filename);
|
||||
|
||||
/* Create a label for the button */
|
||||
Label label = new Label (label_text);
|
||||
|
||||
/* Pack the image and label into the box */
|
||||
box.PackStart (image, false, false, 3);
|
||||
box.PackStart(label, false, false, 3);
|
||||
|
||||
image.Show();
|
||||
label.Show();
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
|
||||
/* Our usual callback function */
|
||||
static void callback( object obj, EventArgs args)
|
||||
{
|
||||
Console.WriteLine("Hello again - cool button was pressed");
|
||||
}
|
||||
|
||||
/* another callback */
|
||||
static void delete_event (object obj, DeleteEventArgs args)
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
Application.Init();
|
||||
|
||||
/* Create a new window */
|
||||
Window window = new Window ("Pixmap'd Buttons!");
|
||||
|
||||
/* It's a good idea to do this for all windows. */
|
||||
window.DeleteEvent += new DeleteEventHandler (delete_event);
|
||||
|
||||
/* Sets the border width of the window. */
|
||||
window.BorderWidth = 10;
|
||||
|
||||
/* Create a new button */
|
||||
Button button = new Button();
|
||||
|
||||
/* Connect the "clicked" signal of the button to our callback */
|
||||
button.Clicked += new EventHandler (callback);
|
||||
|
||||
/* This calls our box creating function */
|
||||
Widget box = xpm_label_box ("info.xpm", "cool button");
|
||||
|
||||
/* Pack and show all our widgets */
|
||||
box.Show();
|
||||
|
||||
button.Add(box);
|
||||
|
||||
button.Show();
|
||||
|
||||
window.Add(button);
|
||||
|
||||
window.ShowAll();
|
||||
|
||||
/* Rest in gtk_main and wait for the fun to begin! */
|
||||
Application.Run();
|
||||
}
|
||||
}
|
||||
}
|
92
sample/tutorial/buttons/info.xpm
Normal file
92
sample/tutorial/buttons/info.xpm
Normal file
|
@ -0,0 +1,92 @@
|
|||
/* XPM */
|
||||
static char *openfile[] = {
|
||||
/* width height num_colors chars_per_pixel */
|
||||
" 20 19 66 2",
|
||||
/* colors */
|
||||
".. c None",
|
||||
".# c #000000",
|
||||
".a c #dfdfdf",
|
||||
".b c #7f7f7f",
|
||||
".c c #006f6f",
|
||||
".d c #00efef",
|
||||
".e c #009f9f",
|
||||
".f c #004040",
|
||||
".g c #00bfbf",
|
||||
".h c #ff0000",
|
||||
".i c #ffffff",
|
||||
".j c #7f0000",
|
||||
".k c #007070",
|
||||
".l c #00ffff",
|
||||
".m c #00a0a0",
|
||||
".n c #004f4f",
|
||||
".o c #00cfcf",
|
||||
".p c #8f8f8f",
|
||||
".q c #6f6f6f",
|
||||
".r c #a0a0a0",
|
||||
".s c #7f7f00",
|
||||
".t c #007f7f",
|
||||
".u c #5f5f5f",
|
||||
".v c #707070",
|
||||
".w c #00f0f0",
|
||||
".x c #009090",
|
||||
".y c #ffff00",
|
||||
".z c #0000ff",
|
||||
".A c #00afaf",
|
||||
".B c #00d0d0",
|
||||
".C c #00dfdf",
|
||||
".D c #005f5f",
|
||||
".E c #00b0b0",
|
||||
".F c #001010",
|
||||
".G c #00c0c0",
|
||||
".H c #000f0f",
|
||||
".I c #00007f",
|
||||
".J c #005050",
|
||||
".K c #002f2f",
|
||||
".L c #dfcfcf",
|
||||
".M c #dfd0d0",
|
||||
".N c #006060",
|
||||
".O c #00e0e0",
|
||||
".P c #00ff00",
|
||||
".Q c #002020",
|
||||
".R c #dfc0c0",
|
||||
".S c #008080",
|
||||
".T c #001f1f",
|
||||
".U c #003f3f",
|
||||
".V c #007f00",
|
||||
".W c #00000f",
|
||||
".X c #000010",
|
||||
".Y c #00001f",
|
||||
".Z c #000020",
|
||||
".0 c #00002f",
|
||||
".1 c #000030",
|
||||
".2 c #00003f",
|
||||
".3 c #000040",
|
||||
".4 c #00004f",
|
||||
".5 c #000050",
|
||||
".6 c #00005f",
|
||||
".7 c #000060",
|
||||
".8 c #00006f",
|
||||
".9 c #000070",
|
||||
"#. c #7f7f80",
|
||||
"## c #9f9f9f",
|
||||
/* pixels */
|
||||
"........................................",
|
||||
"........................................",
|
||||
"........................................",
|
||||
".......................#.#.#............",
|
||||
".....................#.......#...#......",
|
||||
"...............................#.#......",
|
||||
".......#.#.#.................#.#.#......",
|
||||
".....#.y.i.y.#.#.#.#.#.#.#..............",
|
||||
".....#.i.y.i.y.i.y.i.y.i.#..............",
|
||||
".....#.y.i.y.i.y.i.y.i.y.#..............",
|
||||
".....#.i.y.i.y.#.#.#.#.#.#.#.#.#.#.#....",
|
||||
".....#.y.i.y.#.s.s.s.s.s.s.s.s.s.#......",
|
||||
".....#.i.y.#.s.s.s.s.s.s.s.s.s.#........",
|
||||
".....#.y.#.s.s.s.s.s.s.s.s.s.#..........",
|
||||
".....#.#.s.s.s.s.s.s.s.s.s.#............",
|
||||
".....#.#.#.#.#.#.#.#.#.#.#..............",
|
||||
"........................................",
|
||||
"........................................",
|
||||
"........................................"
|
||||
};
|
11
sample/tutorial/filesel/Makefile
Normal file
11
sample/tutorial/filesel/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
CSC = mcs
|
||||
|
||||
DLLS = -r glib-sharp.dll \
|
||||
-r gtk-sharp.dll \
|
||||
-r System.Drawing.dll
|
||||
|
||||
all:
|
||||
$(CSC) /unsafe $(DLLS) filesel.cs
|
||||
clean:
|
||||
rm -f *.exe
|
69
sample/tutorial/filesel/filesel.cs
Normal file
69
sample/tutorial/filesel/filesel.cs
Normal file
|
@ -0,0 +1,69 @@
|
|||
// filesel.cs - Gtk# Tutorial example
|
||||
//
|
||||
// Author: Johannes Roith <johannes@jroith.de>
|
||||
//
|
||||
// (c) 2002 Johannes Roith
|
||||
|
||||
namespace GtkSharpTutorial {
|
||||
|
||||
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
|
||||
public class filesel
|
||||
{
|
||||
|
||||
static FileSelection filew;
|
||||
|
||||
/* Get the selected filename and print it to the console */
|
||||
|
||||
static void file_ok_sel_event( object obj, EventArgs args )
|
||||
{
|
||||
Console.WriteLine("{0}\n",filew.Filename);
|
||||
}
|
||||
|
||||
static void delete_event (object obj, DeleteEventArgs args)
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
static void cancel_event (object obj, EventArgs args)
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
|
||||
Application.Init ();
|
||||
|
||||
|
||||
/* Create a new file selection widget */
|
||||
filew = new FileSelection("File selection");
|
||||
|
||||
filew.DeleteEvent += new DeleteEventHandler (delete_event);
|
||||
|
||||
/* Connect the ok_button to file_ok_sel function */
|
||||
filew.OkButton.Clicked +=new EventHandler (file_ok_sel_event);
|
||||
|
||||
/* Connect the cancel_button to destroy the widget */
|
||||
|
||||
filew.CancelButton.Clicked +=new EventHandler (cancel_event);
|
||||
|
||||
|
||||
/* Lets set the filename, as if this were a save dialog, and we are giving
|
||||
a default filename */
|
||||
|
||||
filew.Filename = "penguin.png";
|
||||
|
||||
filew.Show();
|
||||
|
||||
Application.Run();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
11
sample/tutorial/frame/Makefile
Normal file
11
sample/tutorial/frame/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
CSC = mcs
|
||||
|
||||
DLLS = -r glib-sharp.dll \
|
||||
-r gtk-sharp.dll \
|
||||
-r System.Drawing.dll
|
||||
|
||||
all:
|
||||
$(CSC) /unsafe $(DLLS) frame.cs
|
||||
clean:
|
||||
rm -f *.exe
|
66
sample/tutorial/frame/frame.cs
Normal file
66
sample/tutorial/frame/frame.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
// frame.cs - Gtk# Tutorial example
|
||||
//
|
||||
// Author: Johannes Roith <johannes@jroith.de>
|
||||
//
|
||||
// (c) 2002 Johannes Roith
|
||||
|
||||
namespace GtkSharpTutorial {
|
||||
|
||||
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
|
||||
public class frame
|
||||
{
|
||||
|
||||
static void delete_event (object obj, DeleteEventArgs args)
|
||||
{
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
public static void Main( string[] args)
|
||||
{
|
||||
|
||||
/* Initialise GTK */
|
||||
Application.Init();
|
||||
|
||||
/* Create a new window */
|
||||
Window window = new Window ("Frame Example");
|
||||
|
||||
/* Here we connect the "destroy" event to a signal handler */
|
||||
window.DeleteEvent += new DeleteEventHandler (delete_event);
|
||||
|
||||
window.SetSizeRequest(300, 300);
|
||||
/* Sets the border width of the window. */
|
||||
window.BorderWidth= 10;
|
||||
|
||||
/* Create a Frame */
|
||||
Frame frame = new Frame("MyFrame");
|
||||
window.Add(frame);
|
||||
|
||||
/* Set the frame's label */
|
||||
frame.Label = "GTK Frame Widget";
|
||||
|
||||
/* Align the label at the right of the frame */
|
||||
|
||||
frame.SetLabelAlign((float)1.0,(float)0.0);
|
||||
|
||||
/* Set the style of the frame */
|
||||
frame.ShadowType = (ShadowType) 4;
|
||||
|
||||
frame.Show();
|
||||
|
||||
/* Display the window & all widgets*/
|
||||
window.ShowAll();
|
||||
|
||||
/* Enter the event loop */
|
||||
Application.Run();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
11
sample/tutorial/helloworld/Makefile
Normal file
11
sample/tutorial/helloworld/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
CSC = mcs
|
||||
|
||||
DLLS = -r glib-sharp.dll \
|
||||
-r gtk-sharp.dll \
|
||||
-r System.Drawing.dll
|
||||
|
||||
all:
|
||||
$(CSC) /unsafe $(DLLS) helloworld.cs
|
||||
clean:
|
||||
rm -f *.exe
|
83
sample/tutorial/helloworld/helloworld.cs
Normal file
83
sample/tutorial/helloworld/helloworld.cs
Normal file
|
@ -0,0 +1,83 @@
|
|||
// helloworld.cs - Gtk# Tutorial example
|
||||
//
|
||||
// Author: Johannes Roith <johannes@jroith.de>
|
||||
//
|
||||
// (c) 2002 Johannes Roith
|
||||
|
||||
namespace GtkSharpTutorial {
|
||||
|
||||
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 ();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
sample/tutorial/helloworld2/Makefile
Normal file
11
sample/tutorial/helloworld2/Makefile
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
CSC = mcs
|
||||
|
||||
DLLS = -r glib-sharp.dll \
|
||||
-r gtk-sharp.dll \
|
||||
-r System.Drawing.dll
|
||||
|
||||
all:
|
||||
$(CSC) /unsafe $(DLLS) helloworld2.cs
|
||||
clean:
|
||||
rm -f *.exe
|
100
sample/tutorial/helloworld2/helloworld2.cs
Normal file
100
sample/tutorial/helloworld2/helloworld2.cs
Normal file
|
@ -0,0 +1,100 @@
|
|||
// helloworld2.cs - Gtk# Tutorial example
|
||||
//
|
||||
// Author: Johannes Roith <johannes@jroith.de>
|
||||
//
|
||||
// (c) 2002 Johannes Roith
|
||||
|
||||
namespace GtkSharpTutorial {
|
||||
|
||||
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
|
||||
public class helloworld2
|
||||
{
|
||||
|
||||
/* Our new improved callback. The data is extracted from obj and
|
||||
* is printed to stdout. */
|
||||
|
||||
static void callback( object obj, EventArgs args)
|
||||
{
|
||||
Button mybutton = (Button) obj;
|
||||
Console.WriteLine("Hello again - {0} was pressed", (string) mybutton.Label);
|
||||
// Have to figure out, how to recieve button name
|
||||
}
|
||||
|
||||
/* Exit event */
|
||||
static void delete_event (object obj, DeleteEventArgs args)
|
||||
{
|
||||
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");
|
||||
|
||||
/* This is a new call, which just resets the title of our
|
||||
* new window to "Hello Buttons!" */
|
||||
window.Title ="Hello Buttons!";
|
||||
|
||||
/* Here we just set a handler for delete_event that immediately
|
||||
* exits GTK. */
|
||||
window.DeleteEvent += new DeleteEventHandler (delete_event);
|
||||
|
||||
/* Sets the border width of the window. */
|
||||
window.BorderWidth = 10;
|
||||
|
||||
/* We create a box to pack widgets into. This is described in detail
|
||||
* in the "packing" section. The box is not really visible, it
|
||||
* is just used as a tool to arrange widgets. */
|
||||
HBox box1 = new HBox (false, 0);
|
||||
|
||||
/* Put the box into the main window. */
|
||||
window.Add (box1);
|
||||
|
||||
/* Creates a new button with the label "Button 1". */
|
||||
ToggleButton button1 = new ToggleButton ("Button 1");
|
||||
|
||||
/* Now when the button is clicked, we call the "callback" event
|
||||
* with a pointer to "button 1" as its argument */
|
||||
button1.Clicked += new EventHandler (callback);
|
||||
|
||||
/* Instead of gtk_container_add, we pack this button into the invisible
|
||||
* box, which has been packed into the window. */
|
||||
box1.PackStart (button1, true, true, 0);
|
||||
|
||||
/* Always remember this step, this tells GTK that our preparation for
|
||||
* this button is complete, and it can now be displayed. */
|
||||
button1.Show();
|
||||
|
||||
/* Do these same steps again to create a second button */
|
||||
Button button2 = new Button ("Button 2");
|
||||
|
||||
/* Call the same callback function with a different argument,
|
||||
* passing a pointer to "button 2" instead. */
|
||||
button2.Clicked += new EventHandler (callback);
|
||||
|
||||
box1.PackStart (button2, true, true, 0);
|
||||
|
||||
/* The order in which we show the buttons is not really important, but I
|
||||
* recommend showing the window last, so it all pops up at once. */
|
||||
|
||||
window.ShowAll ();
|
||||
|
||||
/* Rest in Application.Run and wait for the fun to begin! */
|
||||
Application.Run();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue