If I understand correctly, you would like to be able to reset PrinterName to the default printer (1) without re-creating your PrintDocument and (2) after you possibly already installed it on something else or (3) when the printer the default could have been changed since the first PrintDocument was created (so you cannot rely on simple caching of the default values โโset by the target instance after the initial construction).
In this case, searching โC # gets the default printer nameโ opens the following excellent entry in stackoverflow: What is the best way to get the default printer in .NET
Based on the sample provided in the upper voting answer, and considering that you already have an existing PrintDocument with some settings that you do not want to recreate; you can create a new instance of the PrinterSettings class for the sole purpose of copying the default printer name.
// Create a new instance of the PrinterSettings class, which // we will only use to fetch the default printer name System.Drawing.Printing.PrinterSettings newSettings = new System.Drawing.Printing.PrinterSettings(); // Copy the default printer name from our newSettings instance into our // pre-existing PrintDocument instance without recreating the // PrintDocument or the PrintDocument PrinterSettings classes. existingPrintDocumentInstance.PrinterSettings.PrinterName = newSettings.PrinterName;
You can view the related post for alternative methods like WMI, but I think this is the simplest and cleanest solution for you.
source share