Last change
on this file since 1774 was 1246, checked in by Sam Habiel, 13 years ago |
Adding Enhanced Print Preview to Repo
|
File size:
1.4 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using System.Drawing.Printing;
|
---|
5 | using System.Drawing;
|
---|
6 |
|
---|
7 | namespace PrintPreviewDemo {
|
---|
8 | class SampleDocument {
|
---|
9 |
|
---|
10 | const int LineHeight = 30;
|
---|
11 | const int LinesToPrint = 300;
|
---|
12 |
|
---|
13 |
|
---|
14 | PrintDocument pdoc;
|
---|
15 | int Lines = 0;
|
---|
16 |
|
---|
17 | public PrintDocument PrintDocument { get { return pdoc; } }
|
---|
18 |
|
---|
19 | public SampleDocument() {
|
---|
20 | pdoc = new PrintDocument();
|
---|
21 | pdoc.BeginPrint += new PrintEventHandler(pdoc_BeginPrint);
|
---|
22 | pdoc.PrintPage += new PrintPageEventHandler(pdoc_PrintPage);
|
---|
23 | }
|
---|
24 |
|
---|
25 | void pdoc_BeginPrint(object sender, PrintEventArgs e) {
|
---|
26 | Lines = 0;
|
---|
27 | }
|
---|
28 |
|
---|
29 | void pdoc_PrintPage(object sender, PrintPageEventArgs e) {
|
---|
30 | int CurrentY = e.MarginBounds.Top;
|
---|
31 | Font f = new Font("Arial", 12);
|
---|
32 | Rectangle r;
|
---|
33 | while (CurrentY < e.MarginBounds.Bottom - LineHeight && Lines <= LinesToPrint) {
|
---|
34 | r = new Rectangle(e.MarginBounds.Left, CurrentY, e.MarginBounds.Width, LineHeight);
|
---|
35 | e.Graphics.DrawRectangle(Pens.Black, r);
|
---|
36 | e.Graphics.DrawString("Row " + Lines.ToString(), f, Brushes.Black, r);
|
---|
37 | CurrentY += LineHeight;
|
---|
38 | Lines++;
|
---|
39 | }
|
---|
40 | e.HasMorePages = (Lines < LinesToPrint);
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | }
|
---|
45 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.