Printing Without A Dialog Box

It is also possible to print a document without user interaction. This is done by assigning all required options to a PrintDocument object, and then passing it to the TextControl.Print method. This code sample will send page 1 of a document to the default printer:

[C#]
private void mnuFile_Print_WithoutDialog_Click(object sender, System.EventArgs e)
{
    PrintDocument myPrintDocument = new PrintDocument();
    myPrintDocument.PrinterSettings.FromPage = 1;
    myPrintDocument.PrinterSettings.ToPage = 1;
    txTextControl1.Print(myPrintDocument);
}
[Visual Basic]
Private Sub mnuFile_Print_WithoutDialog_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuFile_Print_WithoutDialog.Click
    Dim myPrintDocument As New System.Drawing.Printing.PrintDocument()
    myPrintDocument.PrinterSettings.FromPage = 1
    myPrintDocument.PrinterSettings.ToPage = 1
    TxTextControl1.Print(myPrintDocument)
End Sub
[Delphi]
procedure Form1.mnuFile_Print_WithoutDialog_Click(sender: System.Object;
    e: System.EventArgs);
var
    myPrintDocument : System.Drawing.Printing.PrintDocument;

begin
    myPrintDocument := System.Drawing.Printing.PrintDocument.Create;
    myPrintDocument.PrinterSettings.FromPage := 1;
    myPrintDocument.PrinterSettings.ToPage := 1;
    TxTextControl1.Print(myPrintDocument);
end;

<< Previous