forked from SMAH1/smah1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintToGraphicsForm.cs
More file actions
118 lines (102 loc) · 3.75 KB
/
PrintToGraphicsForm.cs
File metadata and controls
118 lines (102 loc) · 3.75 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using SMAH1.Forms.DataGridViewComponent;
using SMAH1.Print;
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace HowToWork
{
public partial class PrintToGraphicsForm : Form
{
#region class Page
class Page
{
string name;
Image image;
public string Name { get { return name; } }
public Image Image { get { return image; } }
public override string ToString()
{
return Name;
}
public Page(string name, Image image)
{
this.name = name;
this.image = image;
if (image == null)
throw new ArgumentNullException("image");
}
}
#endregion
DataTable dt = null;
public PrintToGraphicsForm()
{
InitializeComponent();
dgv.AutoGenerateColumns = false;
}
private void PrintToImageForm_Load(object sender, EventArgs e)
{
dt = new DataTable("Test");
dt.Columns.Add("Number", typeof(Int32));
dt.Columns.Add("Name", typeof(String));
dt.Columns.Add("Family", typeof(String));
dt.Columns.Add("Status", typeof(Int32));
dt.Rows.Add(1, "Ali", "Mohamadi", DataGridViewProgressCellState.Queue);
dt.Rows.Add(5, "Sara", "Sarvi", DataGridViewProgressCellState.Process);
dt.Rows.Add(4, "Mohsen", "Saba", DataGridViewProgressCellState.Finish);
dt.Rows.Add(10, "Rahim", "vahed", 0);
dt.Rows.Add(10, "Behzad", "Khaki", 25);
dt.Rows.Add(9, "Mina", "mashhadi", 50);
dt.Rows.Add(6, "Zahra", "Tavassoly", 75);
dt.Rows.Add(20, "Rostam", "Torki", DataGridViewProgressCellState.Error);
dgv.DataSource = dt;
}
private void btnPrint_Click(object sender, EventArgs e)
{
string sTitle = txtTitle.Text.Trim();
PrintToGraphics prn = new PrintToGraphics(dt, this.Font,
int.Parse(txtWidth.Text), int.Parse(txtHeight.Text), 10, 20, false,
(sTitle.Length > 0),
null, Color.Black, false, new Padding(3), 1f);
lstPage.Items.Clear();
lstPage.SelectedIndex = -1;
bool bDraw = true;
bool bFirstPage = true;
int num = 0;
while (bDraw)
{
num++;
Bitmap bmp = new Bitmap(int.Parse(txtWidth.Text), int.Parse(txtHeight.Text),
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (Graphics gr = Graphics.FromImage(bmp))
{
if (bFirstPage)
{
bDraw = prn.Draw(gr, 10, 10, sTitle, true);
bFirstPage = false;
}
else
{
bDraw = prn.Draw(gr, 0, 0, string.Empty, false);
}
lstPage.Items.Add(new Page("Page " + num, bmp));
}
}
if (lstPage.Items.Count > 0)
lstPage.SelectedIndex = 0;
}
private void lstPage_SelectedIndexChanged(object sender, EventArgs e)
{
if (lstPage.SelectedIndex == -1)
{
picPage.Image = null;
picPage.Size = new Size(1, 1);
}
else
{
Image img = ((Page)lstPage.SelectedItem).Image;
picPage.Image = img;
}
}
}
}