~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Main/Base/Project/Src/Util/WindowsFormsPrinting.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using ICSharpCode.Core;
 
5
using System;
 
6
using System.Drawing.Printing;
 
7
using System.Windows.Forms;
 
8
using ICSharpCode.SharpDevelop.Gui;
 
9
 
 
10
namespace ICSharpCode.SharpDevelop.Util
 
11
{
 
12
        /// <summary>
 
13
        /// Allows printing using the IPrintable interface.
 
14
        /// </summary>
 
15
        public class WindowsFormsPrinting
 
16
        {
 
17
                public static void Print(IPrintable printable)
 
18
                {
 
19
                        using (PrintDocument pdoc = printable.PrintDocument) {
 
20
                                if (pdoc != null) {
 
21
                                        using (PrintDialog ppd = new PrintDialog()) {
 
22
                                                ppd.Document  = pdoc;
 
23
                                                ppd.AllowSomePages = true;
 
24
                                                if (ppd.ShowDialog(ICSharpCode.SharpDevelop.Gui.WorkbenchSingleton.MainWin32Window) == DialogResult.OK) { // fixed by Roger Rubin
 
25
                                                        pdoc.Print();
 
26
                                                }
 
27
                                        }
 
28
                                } else {
 
29
                                        MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Commands.Print.CreatePrintDocumentError}");
 
30
                                }
 
31
                        }
 
32
                }
 
33
                
 
34
                public static void PrintPreview(IPrintable printable)
 
35
                {
 
36
                        using (PrintDocument pdoc = printable.PrintDocument) {
 
37
                                if (pdoc != null) {
 
38
                                        PrintPreviewDialog ppd = new PrintPreviewDialog();
 
39
                                        ppd.TopMost   = true;
 
40
                                        ppd.Document  = pdoc;
 
41
                                        ppd.Show(WorkbenchSingleton.MainWin32Window);
 
42
                                } else {
 
43
                                        MessageService.ShowError("${res:ICSharpCode.SharpDevelop.Commands.Print.CreatePrintDocumentError}");
 
44
                                }
 
45
                        }
 
46
                }
 
47
        }
 
48
}