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
| private void OnPrintClick(object sender, EventArgs e)
{
try
{
stringToPrint = new StringReader(TbTexteNew.Text);
pdPrint.Document = PDDocument;
try
{
DialogResult result = pdPrint.ShowDialog();
printFont = new Font("Arial", 10);
PDDocument.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
// If the result is OK then print the document.
if (result == DialogResult.OK)
{
PDDocument.Print();
}
}
finally
{
stringToPrint.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
float count = 0;
float countColonne=0;
float count2=0;
float colonnePerLigne=80;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null ;
printFont.Size = 10;
linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
while (count < linesPerPage && ((line = stringToPrint.ReadLine()) != null))
{
yPos = topMargin + (count * printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, yPos, new StringFormat());
count++;
}
if (line == null)
{
ev.HasMorePages = false;
}
else
{
ev.HasMorePages = true;
}
} |
Partager