C # Setting the print area for an envelope

I am trying to perform a very simple operation:

  • Get a list of local printers, allow the user to choose (Got it)

  • Select envelope tray for manual feed

  • Enter the customer address for the specific envelope size (4 1/8 x 9 1/2/03982) on the printer with manual envelope feed.

I have no experience with the System.Drawing.Printing class, so please forgive my ignorance of the topic.

I am fooling myself with the code that I found below, I was playing with: Rectangle(20, 20, 200, etc.));but could not figure out how to subtract it to the appropriate supply or get an envelope tray.

Rectangle class

EDIT - Working Code (Thanks icemanind for pointing me in the right direction.

   //Load
   foreach (String printer in PrinterSettings.InstalledPrinters) {
          printersList.Items.Add(printer.ToString());
    }

    private void btPrint_Click(object sender, EventArgs e)
    {
            var pd = new PrintDocument();
            //Set PrinterName as the selected printer in the printers list
            pd.PrinterSettings.PrinterName = printersList.SelectedItem.ToString();
            //pd.DefaultPageSettings.Margins = new Margins(200, 200, 200, 200);
            pd.DefaultPageSettings.Landscape = true;
            pd.DefaultPageSettings.PaperSize.RawKind = 6;
            pd.PrintPage += pd_PrintPage;
            pd.Print();
    }

    public void pd_PrintPage(object sender, PrintPageEventArgs ev)
    {
            //Get Address From Database or Pass In
            var vnId = Lnq.Orders.Where(a => a.ID == OrdId).Select(a => a.fk_ClientAttID).FirstOrDefault();
            var a = Lnq.Clients.Where(a => a.ID == vnId).Select(a => new {a.Name, a.Addy1, a.City, a.State, a.Zip});
            foreach (var v in e)
            {
                var g = ev.Graphics;
                var font = new Font("Arial", 12);
                var brush = new SolidBrush(Color.Black);
                g.DrawString(a.Name + "\n" + a.Addy1  + "\n" + a.City + ", " 
                             + a.State + " " + a.Zip, font, brush,
                             new Rectangle(500, 400, 650, 650));
            }
    }
+4
source share
1

# PaperSourceKind , . ManualFeed, Manually fed envelope. RawKind 6, ManualFeed.

, , . .

+4

All Articles