打印超出屏幕高度的表格. [英] Printing a Form that extends past the screen height.

查看:129
本文介绍了打印超出屏幕高度的表格.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个表格,随着用户控件的添加,表格的高度会增加,这取决于检索和显示的数据.问题在于表格总是会超出屏幕高度,而当尝试打印表格时,我只能捕获屏幕上显示的内容.有没有办法捕获整个表格并进行打印?

我一直在使用以下代码:

打印预览...

Hi,

I have a form that that grows in height as user controls are added to form depending on data retrieved and presented. The problem is that the form always grows past the screen height and when trying to print the form I''m only able to capture what''s being displayed on the screen. Is there are way to capture the entire form and print it?

I''ve been using the following code:

Print Preview ...

private void buttonPrintPreview_Click(object sender, EventArgs e)
{
    PrintPreviewDialog dlg = new PrintPreviewDialog();
    PrintDocument pd = new PrintDocument();
    pd.PrintPage += new PrintPageEventHandler(PrintImage);
    dlg.Document = pd;
    if (dlg.ShowDialog() == DialogResult.OK)
    {
        pd.Print();
    }
}



打印...



Print ...

private void buttonPrint_Click(object sender, EventArgs e)
{
    PrintDialog dlg = new PrintDialog();
    PrintDocument pd = new PrintDocument();
    pd.PrintPage += new PrintPageEventHandler(PrintImage);
    dlg.Document = pd;
    if (dlg.ShowDialog() == DialogResult.OK)
    {
        pd.Print();
    }
}



打印图像...



Print Image ...

void PrintImage(object o, PrintPageEventArgs e)
{
    int width = this.Width;
    int height = this.Height;

    Rectangle bounds = new Rectangle(0, 0, width, height);
    Bitmap img = new Bitmap(width, height);

    this.DrawToBitmap(img, bounds);

    float WidthPer, HeightPer;
    int NewWidth, NewHeight;
    int pageWidth = e.PageBounds.Width-100;
    int pageHeight = e.PageBounds.Height-100;

    float thumbnailAspectRatio = (float)pageWidth / pageHeight;
    float origImageAspectRatio = (float)width / height;

    if (thumbnailAspectRatio < origImageAspectRatio)
    {
        NewWidth = pageWidth;
        WidthPer = (float)pageWidth / width;
        NewHeight = Convert.ToInt32(height * WidthPer);
    }
    else
    {
        NewHeight = pageHeight;
        HeightPer = (float)pageHeight / height;
        NewWidth = Convert.ToInt32(width * HeightPer);
    }

    e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
    e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
    e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
    Rectangle oRectangle = new Rectangle(50, 50, NewWidth, NewHeight);
    e.Graphics.DrawImage(img, oRectangle);
}

推荐答案

所以您基本上是在打印屏幕快照?不好.

您应该基于数据创建打印文档.

因此,您要遍历每个数据字段并将其绘制在所需的打印文档上.这不是那么简单,因为您将需要计算位置并考虑分页符.

我建议您创建几个帮助程序"类,以存储数据值列表(和匹配的标签)

然后您打印文档事件就可以遍历它们,并在换行上绘制每个值(对于非常简单的布局)

在绘制每个控件之前,您将需要检查预期位置是否在可打印区域的区域中.如果不是,则需要添加新页面并继续绘图.

也许是链接 [
So you are basically printing a screen shot? not good.

You should be creating a print document based on the data.

so you go through each data field and draw that on the print document where you want it. This is not so simple as you will need to calculate positioning and also take page breaks into account.

I would suggest you create a couple of ''helper'' classes that you can store a list of data values (and matching labels)

And then you print document event can loop through them and draw each value on a new line (for a very simple layout)

Before you draw each control you will want to check if the intended position is in the region of the printable area. If not you need to add a new page and continue drawing.

Maybe a link[^] will help you better with this...


这篇关于打印超出屏幕高度的表格.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆