问题描述
我C#打印时候想把FORM中的Controls中的控件内容也打印出来然后在打印DataGridView中的表单不是水晶报表怎么能都实现这一功能这是我部分代码我现在想传FORM取其中的Controls能实现吗?publicstaticvoidPrint_DataGridView(DataGridViewdgv1){PrintPreviewDialogppvw;PrintDialogpd;PageSetupDialogpsd;try{//GettingDataGridViewobjecttoprintdgv=dgv1;//GettingallCoulmnsNamesintheDataGridViewAvailableColumns.Clear();foreach(DataGridViewColumncindgv.Columns){if(!c.Visible)continue;AvailableColumns.Add(c.HeaderText);}//ShowingthePrintOptionFormPrintOptionsdlg=newPrintOptions(AvailableColumns);if(dlg.ShowDialog()!=DialogResult.OK)return;PrintTitle=dlg.PrintTitle;PrintAllRows=dlg.PrintAllRows;FitToPageWidth=dlg.FitToPageWidth;SelectedColumns=dlg.GetSelectedColumns();psd=newPageSetupDialog();PageSettingsps=newPageSettings();psd.PageSettings=ps;psd.ShowDialog();//psd.PageSettings.Landscape=true;printDoc.DefaultPageSettings.Landscape=psd.PageSettings.Landscape;printDoc.DefaultPageSettings.PaperSize=psd.PageSettings.PaperSize;RowsPerPage=0;ppvw=newPrintPreviewDialog();ppvw.Document=printDoc;//ShowingthePrintPreviewPageprintDoc.BeginPrint+=newSystem.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);printDoc.PrintPage+=newSystem.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);//if(ppvw.ShowDialog()!=DialogResult.OK)//{//printDoc.BeginPrint-=newSystem.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);//printDoc.PrintPage-=newSystem.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);//return;//}ppvw.ShowDialog();//PrintingtheDocumnetpd=newPrintDialog();if(pd.ShowDialog()==DialogResult.OK){printDoc.Print();}//printDoc.Print();printDoc.BeginPrint-=newSystem.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);printDoc.PrintPage-=newSystem.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);}catch(Exceptionex){MessageBox.Show(ex.Message,"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);}finally{}}
解决方案
解决方案二:
vb都能實現這個功能了,c#也不是問題吧.