PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 15, 2022

[FIXED] How to set the source of paper for a printer?

 September 15, 2022     c#, printing, winforms     No comments   

Issue

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'


Solution

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 };


Answered By - Ekas
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing