C#打印一个table

来源:百度知道 编辑:UC知道 时间:2024/05/02 05:07:05
protected void Button1_Click(object sender, EventArgs e)
{
System.Windows.Forms.PrintDialog printdialog1 = new System.Windows.Forms.PrintDialog();
PrintDocument MyPrintDoc = new PrintDocument();
MyPrintDoc.PrintPage += new PrintPageEventHandler(MyPrintDoc_PrintPage);
printdialog1.AllowSomePages = true; printdialog1.ShowHelp = true;
printdialog1.Document = MyPrintDoc;
MyPrintDoc.Print();
}
protected void MyPrintDoc_PrintPage(object sender, PrintPageEventArgs e)
{
}

要在这个事件里面怎么写才能在点了按钮以后打印出来这个table的面的东西

myReport= new Report(); //实例化一个报表已经做好的报表
myReport.SetDataSource(加载数据集);
//获取打印设置上面打印机名称
myReport.PrintOptions.PrinterName = PrintDialog1.PrinterSettings.PrinterName;

//设置打印机纸张 下面这句要不要无无谓,在我看来,不起作用
myReport.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4;

//直接打印
myReport.PrintToPrinter(PrintDialog1.PrinterSettings.Copies(获取打印份数), false, 0, 0);

到此也可以打印,可是每次打印的时候出来的都是默认纸盒1的纸张,也可就是说在打印之前的页面设置,仅打印机名起了作用,其它不起作用,不管你之前页面设置是纸盒1还是纸盒2上,每次都从纸盒1进纸,我想问问大家如何根据页面设置动态的选择纸盒来源。
myReport.PrintOptions.PaperSource =在这里应该怎么赋值;

//我是这样赋值,提示不能隐式转换类
myReport.PrintOptions.PaperSource =MyPrintDg.PrinterSettings.PaperSources;

具体赋值信息如下
Report.PrintOptions.PaperSource=xxx

Auto 打印纸张来源于打印机自动选择的纸盒。
Cassette 打印纸张来源于 cassette 纸盒。
Envelope 打印纸张来源于 envelope 纸盒。
EnvManual 打印纸张来源于手动信封送纸器。
FormSource 打印纸张来源于格式源纸盒。
LargeCapacity 打印纸张来源于大容量纸盒。
LargeFmt 打印