I want choose a custom source of paper when printing.
I wrote this code:
PrintDocument pd = new PrintDocument();
pd.PrinterSettings.PrinterName = domainUpDown1.SelectedItem.ToString();
int i = 1;
foreach (int x in consent)
{
pd.PrintPage = new PrintPageEventHandler(this.pd_PrintPage);
pd.PrinterSettings.Copies = Convert.ToInt16(x);
pd.DefaultPageSettings.PaperSource = PaperSourceKind.Upper;
// MessageBox.Show(pd.DefaultPageSettings.PaperSource.ToString());
if (x != 0)
{
pd.Print();
}
i ;
}
but
pd.DefaultPageSettings.PaperSource = PaperSourceKind.Upper;
causes this error:
Error 1 Cannot implicitly convert type 'System.Drawing.Printing.PaperSourceKind' to 'System.Drawing.Printing.PaperSource'
CodePudding user response:
The reason you're getting an error is because you are trying to assign PaperSourceKind.Upper
(which is an enum of type PaperSourceKind
) to pd.DefaultPageSettings.PaperSource
(which is a class of type PaperSource
).
Instead, try
pd.DefaultPageSettings.PaperSource = new PaperSource() { RawKind = (int)PaperSourceKind.Upper };