Print Dialog in C#

In this article, we will learn how to use print dialog box in windows form in C#.

Let's create windows form.

Step 1
In Visual Studio select "File" = > "New" = > "Project..." then select C# Windows Forms Application then click Ok.

create windows form

Step 2
Let's create a Print dialog then you go "View" = > select "ToolBox" (Crtl+Alt+X) = > then select "All Windows Forms" = > Choose "PrintDialog".

print dialog
  1. First of all, we'll know about the "PrintDialog".

    print dialog is mainly used to print any documents in c#. We'll discuss properties and function and events of print dialog write down.

    The following code snippet creates a PrintDialog control object in Runtime.

    PrintDialog pd = new PrintDialog();
    

    ShowDialog() method displays the printdialog box.

    pd.ShowDialog();
    

    Dispose() method released all resources in printdialog box.

    pd.Dispose();
    

    Reset() methods resets all dialog box options to their default values.

    pd.Reset();
    

    "AllowSomePages" Allow the user to choose the page range you would be like to print.

    pd.AllowSomePages = true;
    

    "PrintToFile" Gets or sets a value indicating whether the Print to file check box is selected.

    pd.PrintToFile=true;
    

    "ShowHelp" shows help button.

    pd.ShowHelp = true;
    

    "Document" Set the Document property to the PrintDocument for which the PrintPage Event has been handled. To display the dialog, either this property or the PrinterSettings property must be set

    System.Drawing.Printing.PrintDocument document = new System.Drawing.Printing.PrintDocument();
    pd.Document = document;
    

    "Print()" prints the document.

    document.Print();
    


Write a comment


Name Email Message