mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-28 15:05:34 +00:00
7f3171c814
is now tracking Gnome 2.6. svn path=/trunk/gtk-sharp/; revision=35479
81 lines
1.5 KiB
C#
81 lines
1.5 KiB
C#
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 ();
|
|
}
|
|
}
|