private void button1_Click object sender EventArgs PrintPreviewDialog

 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
private void button1_Click(object sender, EventArgs e)
{
PrintPreviewDialog ppd = new PrintPreviewDialog();
System.Drawing.Printing.PrintDocument doc = new System.Drawing.Printing.PrintDocument();
doc.PrintPage += (s, ev) =>
{
ev.Graphics.Clear(Color.White);
float y = 0;
float sizeY = ev.MarginBounds.Height;
if (myBitmap != null)
{
float x = ((ev.MarginBounds.Right - ev.MarginBounds.Left) / 2) - myBitmap.Width / 2;
ev.Graphics.DrawImage(myBitmap, new PointF(x, y));
y += myBitmap.Size.Height + 40;
}
float align;
if (richTextBox1.SelectionAlignment == HorizontalAlignment.Left) align = 50;
else if (richTextBox1.SelectionAlignment == HorizontalAlignment.Right) align = ev.MarginBounds.Right - 50;
else align = ((ev.MarginBounds.Right - ev.MarginBounds.Left) / 2);
ev.Graphics.DrawString(richTextBox1.Text, richTextBox1.SelectionFont, Brushes.Black, align, y);
ev.Graphics.PageUnit = GraphicsUnit.Inch;
};
ppd.Document = doc;
ppd.ShowDialog();
}