Member 12840328 Ответов: 0

Получение проблемы с печатью документа в форме windows.


words get over lapped and i also not get whole paragraph in paragraph manner. it shows in single line. please see code.


Что я уже пробовал:

private void printToolStripButton_Click(object sender, EventArgs e)
{
        if (printDialog1.ShowDialog() == DialogResult.OK)
        {
            System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
            printDocument1.Print();
        }
}
private int linesPrinted;
private string[] lines;
private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
    char[] param ={ '\n' };
    if (printDialog1.PrinterSettings.PrintRange == PrintRange.Selection)
    {
        lines = richTextBox1.SelectedText.Split(param);
    }
    else
    {
        lines = richTextBox1.Text.Split(param);
    }
    int i = 0;
    char[] trimParam = { '\r' };
    foreach (string s in lines)
    {
        lines[i++] = s.TrimEnd(trimParam);
    }
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    int x = e.MarginBounds.Left;
    int y = e.MarginBounds.Top;
    Brush brush = new SolidBrush(richTextBox1.ForeColor);

    while (linesPrinted < lines.Length)
    {
        e.Graphics.DrawString(lines[linesPrinted++],
            richTextBox1.Font, brush, x, y);
        y += 15;
        if (y >= e.MarginBounds.Bottom)
        {
            e.HasMorePages = true;
            return;
        }
    }

    linesPrinted = 0;
    e.HasMorePages = false;
}

0 Ответов