source: Scheduling/trunk/cs/EnhancedPrintPreview/PrintPreviewDemo/Form1.cs@ 1654

Last change on this file since 1654 was 1246, checked in by Sam Habiel, 13 years ago

Adding Enhanced Print Preview to Repo

File size: 4.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using System.Data;
5using System.Drawing;
6using System.Text;
7using System.Windows.Forms;
8using System.Drawing.Printing;
9using System.Threading;
10using System.Globalization;
11using VR.PrintPreview;
12
13namespace PrintPreviewDemo {
14 public partial class Form1 : Form {
15
16 SampleDocument sample;
17 AdditionalText additionalText;
18 List<AdditionalText> globalAdditionalTextList;
19
20 public Form1() {
21 InitializeComponent();
22 //Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
23 sample = new SampleDocument();
24 additionalText = new AdditionalText("Page $pagenumber");
25 propertyGrid1.SelectedObject = additionalText;
26
27 //Additional text can be stored in a global list and then
28 //assigned through the AdditionalTextList property of the EnhancedPrintPreviewDialog
29 globalAdditionalTextList = new List<AdditionalText>();
30 globalAdditionalTextList.Add(new AdditionalText("Draft", new Font("Arial", 120), Brushes.Red, TextPosition.WaterMark, 0, 0));
31 globalAdditionalTextList.Add(new AdditionalText("Vertical Top Right", new Font("Courier New", 10), Brushes.Blue, TextPosition.VTopRight,0,0));
32 globalAdditionalTextList.Add(new AdditionalText("Vertical Top Left", new Font("Comic sans MS", 16), Brushes.Red, TextPosition.VTopLeft, 0, 0));
33 globalAdditionalTextList.Add(new AdditionalText("Vertical Bottom Left", new Font("Microsoft Sans Serif", 16), Brushes.Green, TextPosition.VBottomLeft, 0, 0));
34 globalAdditionalTextList.Add(new AdditionalText("Vertical Bottom Right", new Font("Thaoma", 14), Brushes.Brown, TextPosition.VBottomRight, 0, 0));
35 globalAdditionalTextList.Add(new AdditionalText("Vertical Middle Right", new Font("Times New Roma", 18), Brushes.Violet, TextPosition.VMiddleRight, 0, 0));
36 globalAdditionalTextList.Add(new AdditionalText("Vertical Middle Left", new Font("Comic sans MS", 16), Brushes.YellowGreen, TextPosition.VMiddleLeft, 0, 0));
37 globalAdditionalTextList.Add(new AdditionalText("Horizontal Top Right", new Font("Courier New", 10), Brushes.Blue, TextPosition.HTopRight, 0, 0));
38 globalAdditionalTextList.Add(new AdditionalText("Horizontal Top Left", new Font("Comic sans MS", 10), Brushes.Red, TextPosition.HTopLeft, 0, 0));
39 globalAdditionalTextList.Add(new AdditionalText("Horizontal Top Center", new Font("Times New Roma", 10), Brushes.Violet, TextPosition.HTopCenter, 0, 0));
40 globalAdditionalTextList.Add(new AdditionalText("Horizontal Bottom Right", new Font("Courier New", 10), Brushes.Blue, TextPosition.HBottomRight, 0, 0));
41 globalAdditionalTextList.Add(new AdditionalText("Horizontal Bottom Left", new Font("Comic sans MS", 10), Brushes.Red, TextPosition.HBottomLeft, 0, 0));
42 globalAdditionalTextList.Add(new AdditionalText("Page $pagenumber")); //uses default font and postion (bottom center)
43 }
44
45 private void btnClassic_Click(object sender, EventArgs e) {
46 MessageBox.Show("If you press the \"print button\" 10 pages will be sent soon to your default printer", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
47 PrintPreviewDialog ClassicPreview = new PrintPreviewDialog();
48 ClassicPreview.Document = sample.PrintDocument;
49 ClassicPreview.ShowDialog();
50 }
51
52 private void btnNew_Click(object sender, EventArgs e) {
53 EnhancedPrintPreviewDialog NewPreview = new EnhancedPrintPreviewDialog();
54 NewPreview.Document = sample.PrintDocument;
55 NewPreview.ShowDialog();
56 }
57
58 private void btnTest_Click(object sender, EventArgs e) {
59 EnhancedPrintPreviewDialog NewPreview = new EnhancedPrintPreviewDialog();
60 NewPreview.Document = sample.PrintDocument;
61 NewPreview.ShowPrinterSettingsButton = chkShowPrinterSettings.Checked;
62 NewPreview.ShowPageSettingsButton = chkShowPageSettings.Checked;
63 NewPreview.ShowPrinterSettingsBeforePrint = chkPrinterSettingBeforePrint.Checked;
64 if (!NewPreview.ShowPrinterSettingsBeforePrint)
65 MessageBox.Show("If you press the \"print button\" 10 pages will be sent soon to your default printer", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
66
67 NewPreview.AdditionalTextList.Add(additionalText);
68 NewPreview.ShowDialog();
69 }
70
71
72 private void btnNewAdditionalText_Click(object sender, EventArgs e) {
73 EnhancedPrintPreviewDialog NewPreview = new EnhancedPrintPreviewDialog();
74 NewPreview.Document = sample.PrintDocument;
75 NewPreview.AdditionalTextList = globalAdditionalTextList;
76 NewPreview.ShowDialog();
77 }
78 }
79}
Note: See TracBrowser for help on using the repository browser.