Как я могу распечатать большой dataGridView / Форма на нескольких страницах? - PullRequest
1 голос
/ 29 февраля 2012

Просто используя Win Forms в C #. Создан Data Grid View и добавлена ​​кнопка печати. Вот мой код для кнопки печати.

private void toolStripButton1_Click(object sender, EventArgs e)
    {
        image = new Bitmap(this.dataGridView1.Width, this.dataGridView1.Height);
        this.dataGridView1.DrawToBitmap(image, new Rectangle(new Point(), this.dataGridView1.Size));
        memStream = new System.IO.MemoryStream();
        printPDialog = new PrintPreviewDialog();

        try
        {
            printFont = new Font("Arial", 10);
            image.Save(memStream, System.Drawing.Imaging.ImageFormat.Bmp);
            image.Save("d:\\Adnan.bmp");
            p = new PrintDocument();
            p.PrintPage += this.p_PrintPage;

            this.printPDialog.Document = p;
            printPDialog.Show();

        }
        catch (System.Runtime.InteropServices.ExternalException ee)
        {

        }

}

    private void p_PrintPage(object sender, PrintPageEventArgs e)
    {
        float linesPerPage = 0;
        float yPos = 0;
        int count = 0;
        float leftMargin = e.MarginBounds.Left;
        float topMargin = e.MarginBounds.Top;
        int? line = null;

        // Calculate the number of lines per page.
        linesPerPage = e.MarginBounds.Height /
           printFont.GetHeight(e.Graphics);   
        e.Graphics.DrawImage(Image.FromStream(memStream), leftMargin, topMargin);

    }


    private void printPDialog_FormClosed(object sender, FormClosedEventArgs e)
    {
        image.Dispose();
        memStream.Dispose();
    }

Проблема в том, что мой DataGridView имеет большой список. У меня есть DataGridView внутри FlowLayoutPanel. Я попытался распечатать FlowLayoutPanel, а также GridView, но в любом случае данные, которые скрыты вертикальной полосой прокрутки, не распечатываются. Проведя часы в Интернете и попробовав VB PowerPacks, я не знаю, что делать.

Вот как данные выглядят в GridView.

enter image description here

1 Ответ

0 голосов
/ 29 февраля 2012

Вот ссылка, по которой вы можете попробовать скачанный пример кода
Как напечатать сетку данных в C # и .NET

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...