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 WPF.TextControl.Print method with an application provided dialog box.

[C#]
private void MenuItem_Click_2(object sender, RoutedEventArgs e)
{
    PrintDialog pDialog = new PrintDialog();
    pDialog.PageRangeSelection = PageRangeSelection.AllPages;
    pDialog.UserPageRangeEnabled = true;

    Nullable<Boolean> print = pDialog.ShowDialog();
    PageRange prRange;

    prRange = pDialog.PageRangeSelection == PageRangeSelection.AllPages ?
        new PageRange(1, textControl1.Pages) : 
        new PageRange(pDialog.PageRange.PageFrom, pDialog.PageRange.PageTo);

    if (print == true)
    {
        textControl1.Print(
        "My print job", 
        pDialog.PrintQueue.Name,
        prRange,
        pDialog.PrintTicket.CopyCount.Value,
        pDialog.PrintTicket.Collation.Value);
     }
}
[Visual Basic]
Private Sub MenuItem_Click_2(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim pDialog As New PrintDialog()
    pDialog.PageRangeSelection = PageRangeSelection.AllPages
    pDialog.UserPageRangeEnabled = True

    Dim print As Nullable(Of [Boolean]) = pDialog.ShowDialog()

    Dim prRange As PageRange

    prRange = If(pDialog.PageRangeSelection = PageRangeSelection.AllPages, _
        New PageRange(1, textControl1.Pages), New PageRange(pDialog.PageRange.PageFrom, pDialog.PageRange.PageTo))

    If print = True Then
        textControl1.Print("My print job", pDialog.PrintQueue.Name, prRange, _
            pDialog.PrintTicket.CopyCount.Value, pDialog.PrintTicket.Collation.Value)
    End If
End Sub