Asp.net crystal report printing instance code

Source: Internet
Author: User

Asp.net crystal report printing instance code
// Try two ways to print the report table. I placed a crystalreportviewer control on form1, named it cryview, and used its built-in "print button" to print the report.
// You have also set a crystalreportdocument named cryreport1, and a button named "start printing" on form1, use it to directly call report printing.

// Initialize cryview, cryreport1, and reportds in the load of form1.
Private void form1_load (object sender, eventargs e)
  {
// Initialize reportds before adding some dtpack data to it.
Datarow reprow1 = reportds. tables ["dtpack"]. newrow ();
Reprow1 ["pname"] = "basic package ";
Reprow1 ["prates"] = 12;
Reprow1 ["nummonth"] = 12;
Reprow1 ["enddate"] = "2011-6-20 ";
Reportds. tables ["dtpack"]. rows. add (reprow1 );
Datarow reprow2 = reportds. tables ["dtpack"]. newrow ();
Reprow2 ["pname"] = "classic video ";
Reprow2 ["prates"] = 2;
Reprow2 ["nummonth"] = 12;
Reprow2 ["enddate"] = "2011-6-20 ";
Reportds. tables ["dtpack"]. rows. add (reprow2 );
// The above are the two test data temporarily added to the table.
// Add other data below
Cryreport1.load ("dtvreport. rpt ");
Cryreport1.setdatasource (reportds. tables ["dtpack"]);
// The following describes how to assign values to several parameter fields in the report.
Cryreport1.setparametervalue ("tuseraddress", "user's home address ");
Cryreport1.setparametervalue ("toperator", "Sun Li ");
Cryreport1.setparametervalue ("tusername", "payer name ");
Cryview. reportsource = cryreport1;
  }
 
Private void button#click (object sender, eventargs e)
  {
System. drawing. printing. printdocument pdoc = new printdocument ();
Int rawkind = 1;
For (int I = 0; I <= pdoc. printersettings. papersizes. count-1; I ++)
  {
If (pdoc. printersettings. papersizes [I]. papername = "reppage ")
{// Here, I used the custom paper name reppage
Rawkind = pdoc. printersettings. papersizes [I]. rawkind;
  }
  }
Reportdocument mydoc = new reportdocument ();
Mydoc. printoptions. papersize = (crystaldecisions. shared. papersize) rawkind;
Pagemargins pmargin = new pagemargins ();
Pmargin. topmargin = 100;
Pmargin. bottommargin = 100;
Pmargin. leftmargin = 10;
Pmargin. rightmargin = 10;
Mydoc. printoptions. applypagemargins (pmargin );
// Defines the boundary. I have already customized the boundary in the report, but the left and right boundary values do not seem to work during printing, there is a lot of free space on the left side of the printed invoice. It is estimated that there should be at least 1 cm. Upper and lower boundaries play a role.
// Add other data below
String fn = "dtvreport. rpt ";
// String fn = application. startuppath + "\ dtvreport. rpt ";
Mydoc. load (fn );
Mydoc. setdatasource (reportds. tables ["dtpack"]);
Mydoc. setparametervalue ("tuseraddress", "user's home address ");
Mydoc. setparametervalue ("toperator", "Sun Li www.111cn.net ");
Mydoc. setparametervalue ("tusername", "payer name ");
Mydoc. printtoprinter (1, false, 0, 0); // start printing all pages
  }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.