以多种形式打印面板数据C#
我在C#Winforms应用程序中有一个面板,我需要在多个页面中打印它的内容。我已经使用了下面的代码,我知道它需要修改的地方,请帮助我与它以多种形式打印面板数据C#,c#,C#,我在C#Winforms应用程序中有一个面板,我需要在多个页面中打印它的内容。我已经使用了下面的代码,我知道它需要修改的地方,请帮助我与它 private void PrintP_Load(object sender, EventArgs e) { tableLayoutPanel1.AutoSize = false; ; tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddRows; Print(thi
private void PrintP_Load(object sender, EventArgs e)
{
tableLayoutPanel1.AutoSize = false; ;
tableLayoutPanel1.GrowStyle = TableLayoutPanelGrowStyle.AddRows;
Print(this.panel2);
this.Close();
}
Bitmap MemoryImage;
int page=0;
public void GetPrintArea(Panel pnl)
{
page = 0;
MemoryImage = new Bitmap(pnl.Width, pnl.Height);
Rectangle rect = new Rectangle(0, 0, pnl.Width, pnl.Height);
pnl.DrawToBitmap(MemoryImage, new Rectangle(0, 0, pnl.Width, pnl.Height));
}
protected override void OnPaint(PaintEventArgs e)
{
if (MemoryImage != null)
{
e.Graphics.DrawImage(MemoryImage, 0, 0);
base.OnPaint(e);
}
}
void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
{
var pagearea = e.PageBounds;
e.Graphics.DrawImage(MemoryImage, new Rectangle(e.PageBounds.Location, e.PageBounds.Size), new Rectangle(e.PageBounds.Location.X, e.PageBounds.Height * page, e.PageBounds.Width, e.PageBounds.Height), GraphicsUnit.Pixel);
e.HasMorePages = e.PageBounds.Height * page < panel2.Size.Height;
page++;
}
public void Print(Panel pnl)
{
panel2 = pnl;
GetPrintArea(pnl);
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
private void PrintP_加载(对象发送方,事件参数e)
{
tableLayoutPanel1.AutoSize=false;
tableLayoutPanel1.GrowthStyle=TableLayoutPanelGrowthStyle.AddRows;
印刷品(本页第2页);
这个。关闭();
}
位图存储器图像;
int page=0;
公共区域(面板pnl)
{
page=0;
MemoryImage=新位图(pnl.Width,pnl.Height);
矩形矩形=新矩形(0,0,pnl.宽度,pnl.高度);
pnl.DrawToBitmap(MemoryImage,新矩形(0,0,pnl.Width,pnl.Height));
}
受保护的覆盖无效OnPaint(PaintEventArgs e)
{
if(MemoryImage!=null)
{
e、 绘图图像(MemoryImage,0,0);
基础漆(e);
}
}
无效打印文档1\u打印页(对象发送方,PrintPageEventArgs e)
{
var pagearea=e.PageBounds;
e、 Graphics.DrawImage(MemoryImage、新矩形(e.PageBounds.Location、e.PageBounds.Size)、新矩形(e.PageBounds.Location.X、e.PageBounds.Height*页、e.PageBounds.Width、e.PageBounds.Height)、GraphicsUnit.Pixel);
e、 HasMorePages=e.PageBounds.Height*页面
请对格式更加敏感。。您可以阅读您是否尝试复制面板及其控件/功能,然后在任何窗体上进行更改时尝试序列化-反序列化。但我甚至不确定表单是否可序列化。如果您只想显示面板的图像,那么代码有什么问题,显示错误?