File: PrintSample.cs

package info (click to toggle)
gtk-sharp2 2.8.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 21,208 kB
  • ctags: 5,843
  • sloc: xml: 245,420; cs: 24,183; sh: 8,547; ansic: 2,739; makefile: 1,582; perl: 1,177
file content (80 lines) | stat: -rw-r--r-- 1,567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using Gtk;
using Gnome;

class PrintSample
{
	TextView tv;
	
	static void Main ()
	{
		new PrintSample ();
	}
	
	PrintSample ()
	{
		Application.Init ();
		Gtk.Window win = new Gtk.Window ("Print sample");
		win.SetDefaultSize (400, 300);
		win.DeleteEvent += new DeleteEventHandler (OnWinDelete);
		
		VBox vbox = new VBox (false, 0);
		win.Add (vbox);
		
		tv = new TextView ();
		tv.Buffer.Text = "Hello World";
		vbox.PackStart (tv, true, true, 0);

		Button print = new Button (Gtk.Stock.Print);
		print.Clicked += new EventHandler (OnPrintClicked);
		vbox.PackStart (print, false, true, 0);	
		
		win.ShowAll ();
		Application.Run ();
	}
	
	void MyPrint (PrintContext gpc)
	{
		gpc.BeginPage ("demo");
		gpc.MoveTo (1, 700);
		gpc.Show (tv.Buffer.Text);
		gpc.ShowPage ();
	}
	
	void OnPrintClicked (object o, EventArgs args)
	{
		PrintJob pj = new PrintJob (PrintConfig.Default ());
		PrintDialog dialog = new PrintDialog (pj, "Print Test", 0);
		int response = dialog.Run ();
		Console.WriteLine ("response: " + response);
		
		if (response == (int) PrintButtons.Cancel) {
			Console.WriteLine ("Canceled");
			dialog.Hide ();
			dialog.Dispose ();
			return;
		}

		PrintContext ctx = pj.Context;
		MyPrint (ctx); 

		pj.Close ();
		
		switch (response) {
		case (int) PrintButtons.Print: 
			pj.Print (); 
			break;
		case (int) PrintButtons.Preview:
			new PrintJobPreview (pj, "Print Test").Show ();
			break;
		}

		dialog.Hide ();
		dialog.Dispose ();
	}
	
	void OnWinDelete (object o, DeleteEventArgs args)
	{
		Application.Quit ();
	}
}