In VB, if you want to print a A4 document, and the content is dynamically obtained from DB, or the DataGrid medium, it is simple to implement, such as the following code (RS represents a Recordset):
Rs. MoveFirst
Printer.papersize = vbPRPSA4
Printer.orientation = vbprorportrait
Printer.fontname = "Courier New "
Printer.fontbold = True
Printer.fontsize =
Printer.print" FQA "
Printer.font Size =
Printer.print "pallet ID:" & Trim (RS ("pallet_id")
NewLine2 = String (M, "")
Mid (newl Ine2, 1, 5) = "no#"
Mid (NewLine2) = "System s/n"
Mid (NewLine2,%) = "box_id"
Mid (NewLine2, = "pallet_id"
While not Rs. EOF
NewLine2 = String (M, "")
Mid (NewLine2, 1, 5) = Trim (rs ("No"))
Mid (NewLine2,) = Trim ( RS ("SN"))
Mid (NewLine2,) = Trim (rs ("box_id"))
Mid (NewLine2, m) = "" & Trim (RS ("pallet_id")
Printer.print NewLine2
Rs. MoveNext
Wend
printer.print NewLine2
Printer.print String (+, "-")
In the above code, if the number of records set, that is, content beyond a page, the program does not have to do any settings, will automatically page, then. NET, how to achieve such a simple function?
Check a lot of information, the Internet search for a long time, found no similar examples, looked at the MSDN, only to find that, to VB.net, VB so good printer disappeared, for the description of MSDN: http://msdn.microsoft.com/zh-tw/ library/cc438273 (vs.71). aspx
"The Printer object in Visual Basic 6.0 is replaced by the PrintDocument component in Visual Basic. NET. The behavior of the two is different, but in most cases the functionality can be replicated. The following table lists the Visual Basic 6.0 properties, methods, and events and their Visual Basic. NET equivalents. If there is no direct peer-to-peer usage, a link is provided to obtain additional information. Unless otherwise noted, all objects are in the System.Drawing namespace. "
The first feeling is that there are better printing features in. NET than this. And more powerful, so began to turn the book, the Internet to find examples, spent a good long time, finally found two examples on the internet, with textbooks (C # Advanced Programming Fourth Edition 25th, VB 2005 Introductory Classic 7th chapter) in the example, almost, Examples are to open the document first, after LoadFile, and then calculate how many lines, then set some properties, and so on, although powerful, but extremely complex, can not be used directly, so had to rewrite their own ...
Print function:
public bool Printdoc ()
{
Try
{
Get what you want to print
String strSQL = "exec [Usp_palletprintdocinfo] '"
+ parameters.strstation + "', '" + Parameters.strpalletid + "";
Dsprintinfo = Dodb.getdataset (strSQL);
if (dsprintinfo.tables[0). Rows.Count < 1 | | DSPRINTINFO.TABLES[1]. Rows.Count < 1)
{
parameters.strmsg = "Get Print information Error";
return false;
}
Print
PrintDocument PrintDocument = new PrintDocument ();
Printdocument.printpage + = new Printpageeventhandler (this.pd_printpage);
Printdocument.print ();
/**/////Print Preview, when debugging, you can save paper through this
PrintPreviewDialog PPD = new PrintPreviewDialog ();
PrintDocument PD = new PrintDocument ();
Pd. PrintPage + = new Printpageeventhandler (this.pd_printpage);
Ppd. Document = PD;
Ppd. ShowDialog ();
return true;
}
catch (Exception ex)
{
Parameters.strmsg = ex. Message.tostring ();
return false;
}
}