问题描述
classDGV_Print{publicclassDataGridViewPrint{privateDataGridView[]dataGridView;privatePrintDocumentprintDocument;privatePageSetupDialogpageSetupDialog;privatePrintPreviewDialogprintPreviewDialog;privateintdgvIndex=0;privateintrowCount=0;privateintcolCount=0;privateintx=0;privateinty=0;inti=0;privateintrowGap=60;privateintleftMargin=50;privateFontfont=newFont("Arial",10);privateFontheadingFont=newFont("Arial",11,FontStyle.Underline);privateFontcaptionFont=newFont("Arial",10,FontStyle.Bold);privateBrushbrush=newSolidBrush(Color.Black);privatestringcellValue="";publicDataGridViewPrint(DataGridView[]dataGridView){this.dataGridView=dataGridView;printDocument=newPrintDocument();printDocument.PrintPage+=newPrintPageEventHandler(this.printDocument_PrintPage);}privatevoidprintDocument_PrintPage(objectsender,System.Drawing.Printing.PrintPageEventArgse){for(;dgvIndex<dataGridView.Length;dgvIndex++){rowCount=dataGridView[dgvIndex].Rows.Count-1;colCount=dataGridView[dgvIndex].ColumnCount;//printheadingsy+=rowGap;x=leftMargin;for(intj=0;j<colCount;j++){if(dataGridView[dgvIndex].Columns[j].Width>0){cellValue=dataGridView[dgvIndex].Columns[j].HeaderText;e.Graphics.FillRectangle(newSolidBrush(Color.LightGray),x,y,dataGridView[dgvIndex].Columns[j].Width,rowGap);e.Graphics.DrawRectangle(Pens.Black,x,y,dataGridView[dgvIndex].Columns[j].Width,rowGap);e.Graphics.DrawString(cellValue,headingFont,brush,x,y);x+=dataGridView[dgvIndex].Columns[j].Width;}}//printallrowsfor(;i<rowCount;i++){y+=rowGap;x=leftMargin;for(intj=0;j<colCount;j++){if(dataGridView[dgvIndex].Columns[j].Width>0){cellValue=dataGridView[dgvIndex].Rows[i].Cells[j].Value.ToString();e.Graphics.DrawRectangle(Pens.Black,x,y,dataGridView[dgvIndex].Columns[j].Width,rowGap);e.Graphics.DrawString(cellValue,font,brush,x,y);x+=dataGridView[dgvIndex].Columns[j].Width;}}if(y>=e.PageBounds.Height-80){//允許多頁打印y=0;e.HasMorePages=true;i++;return;}}y+=rowGap;for(intj=0;j<colCount;j++){e.Graphics.DrawString("",font,brush,x,y);}i=0;}e.HasMorePages=false;}publicPrintDocumentGetPrintDocument(){returnprintDocument;}publicvoidPrint(){try{pageSetupDialog=newPageSetupDialog();pageSetupDialog.Document=printDocument;pageSetupDialog.ShowDialog();printPreviewDialog=newPrintPreviewDialog();printPreviewDialog.Document=printDocument;printPreviewDialog.Height=600;printPreviewDialog.Width=800;printPreviewDialog.ShowDialog();}catch(Exceptione){thrownewException("Printererror."+e.Message);}}}}请问在调用这个DataGridViewPrint的publicDataGridViewPrint(DataGridView[]dataGridView)函数时!!DataGridViewPrint()的括号里面添什么啊!!
解决方案
解决方案二:
DataGridview数组啊。。
解决方案三:
当然是DataGridview类型的数组啊,因为你是这么定义形参的
解决方案四:
引用2楼gsnake2的回复:
当然是DataGridview类型的数组啊,因为你是这么定义形参的
同意楼上