gpt4 book ai didi

c# - 如何将 Winforms DataGrid 打印到纸上?

转载 作者:太空宇宙 更新时间:2023-11-03 22:19:22 24 4
gpt4 key购买 nike

如何将 System.Windows.Forms.DataGrid 打印到纸上?我在 C# 中使用 .NET 3.5 框架

最佳答案

这是一个使用 System.Drawing.Printing.PrintDocument 的例子类(不完整,但展示了如何将所有内容连接在一起):

public class MyForm : Form
{
DataGrid dataGrid1 = new DataGrid();
Button printGrid = new Button();
PrintDocument printDocument1 = new PrintDocument();

public MyForm()
{
printGrid.Click += new EventHandler(printGrid_Click);
printDocument1.PrintPage +=
new PrintPageEventHandler(printDocument1_PrintPage);
}

private void printGrid_Click(System.Object sender, System.EventArgs e)
{
printDocument1.Print();
}

private void printDocument1_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
PaintEventArgs myPaintArgs =
new PaintEventArgs(e.Graphics,
new Rectangle(new Point(0, 0), this.Size));
this.InvokePaint(dataGrid1, myPaintArgs);
}
}

关于c# - 如何将 Winforms DataGrid 打印到纸上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3763116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com