TX Text Control .NET for Windows Forms Documentation

Step 2 - Printing

In this step, a Print button is added to the Address Database form. When this button is clicked, the program will take all records from the sample address database in turn, merge them into the document, and print:

[C#] private void cmdPrint_Click(object sender, System.EventArgs e) { PrintDocument PrintDoc = new PrintDocument(); foreach (DataRow CurrentRow in dsAddress.Tables[0].Rows) { // Merge data from current record foreach (TXTextControl.TextField Field in tx.TextFields) Field.Text = CurrentRow[Field.Name].ToString(); // Print PrintDoc.PrinterSettings.FromPage = 0; PrintDoc.PrinterSettings.ToPage = tx.Pages; tx.Print(PrintDoc); } }
[Visual Basic] Private Sub cmdPrint_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdPrint.Click Dim PrintDoc As New System.Drawing.Printing.PrintDocument Dim CurrentRow As DataRow Dim Field As TXTextControl.TextField For Each CurrentRow In dsAddress.Tables(0).Rows ' Merge data from current record For Each Field In tx.TextFields Field.Text = CurrentRow.Item(Field.Name) Next ' Print PrintDoc.PrinterSettings.FromPage = 0 PrintDoc.PrinterSettings.ToPage = tx.Pages tx.Print(PrintDoc) Next End Sub
[Delphi] procedure TfrmAddressDatabase.cmdPrint_Click(sender: System.Object; e: System.EventArgs); var PrintDoc : System.Drawing.Printing.PrintDocument; CurrentRow : System.Data.DataRow; Field : TXTextControl.TextField; begin PrintDoc := System.Drawing.Printing.PrintDocument.Create; for CurrentRow in dsAddress.Tables[0].Rows do begin // Merge data from current record for Field in tx.TextFields do begin Field.Text := CurrentRow.Item[Field.Name].ToString; end; // Print PrintDoc.PrinterSettings.FromPage := 0; PrintDoc.PrinterSettings.ToPage := tx.Pages; tx.Print(PrintDoc); end; end;

As this happens automatically, the manual navigation buttons and the Merge button from step 1 are no longer required and have been removed. The single label controls have been replaced by a data grid, which provides a better overwiew of the records.

<< Previous Next >>

 
 
 

Products

Support

Downloads

Corporate

Buy Now