Customizing The Print Dialog Box

By default, the print dialog box will be displayed with default options, which is fine for most applications. Should you need to configure the print dialog, for instance to enable or disable options like AllowPrintToFile, ShowHelp, or ShowNetwork, you can use the TextControl.Print method with an application provided dialog box. This code sample will open a print dialog box with the AllowPrintToFile and AllowSomePages options disabled:

[C#]
private void mnuFile_Print_WithCustomizedDialog_Click(object sender, System.EventArgs e)
{
    PrintDialog myPrintDialog = new PrintDialog();
    PrintDocument myPrintDocument = new PrintDocument();
    myPrintDialog.Document = myPrintDocument;
    myPrintDialog.AllowSomePages = false;
    myPrintDialog.AllowPrintToFile = false;
    myPrintDialog.PrinterSettings.FromPage = 1;
    myPrintDialog.PrinterSettings.ToPage = txTextControl1.Pages;
    if (myPrintDialog.ShowDialog() == DialogResult.OK )
    {
        textControl1.Print(myPrintDocument);
    }
}
[Visual Basic]
Private Sub mnuFile_Print_WithCustomizedDialog_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles mnuFile_Print_WithCustomizedDialog.Click
    Dim MyPrintDialog As New PrintDialog()
    Dim MyPrintDocument As New System.Drawing.Printing.PrintDocument()
    MyPrintDialog.Document = MyPrintDocument
    MyPrintDialog.AllowSomePages = False
    MyPrintDialog.AllowPrintToFile = False
    MyPrintDialog.PrinterSettings.FromPage = 1
    MyPrintDialog.PrinterSettings.ToPage = TextControl1.Pages
    If MyPrintDialog.ShowDialog() = DialogResult.OK Then
        TextControl1.Print(MyPrintDocument)
    End If
End Sub
[Delphi]
procedure Form1.mnuFile_Print_WithCustomizedDialog_Click(sender: System.Object;
    e: System.EventArgs);
var
    myPrintDialog : PrintDialog;
    myPrintDocument : System.Drawing.Printing.PrintDocument;

begin
    myPrintDialog := PrintDialog.Create;
    myPrintDocument := System.Drawing.Printing.PrintDocument.Create;
    myPrintDialog.Document := myPrintDocument;
    myPrintDialog.AllowSomePages := False;
    myPrintDialog.AllowPrintToFile := False;
    myPrintDialog.PrinterSettings.FromPage := 1;
    myPrintDialog.PrinterSettings.ToPage := TxTextControl1.Pages;
    If myPrintDialog.ShowDialog = System.Windows.Forms.DialogResult.OK then
        TextControl1.Print(myPrintDocument);
end;

<< Previous Next >>