Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#设置信封的打印区域_C#_Printing - Fatal编程技术网

C#设置信封的打印区域

C#设置信封的打印区域,c#,printing,C#,Printing,我试着做一个非常简单的操作: 获取本地打印机列表,让用户选择(获取此) 选择信封托盘进行手动进纸 在手动信封进纸打印机上按特定信封大小(4 1/8 x 9 1/2/03982)打印客户地址 我没有上过System.Drawing.Printing课程的经验,所以请原谅我对这个话题的无知 我在玩弄下面找到的代码,我一直在玩:Rectangle(20、20、200等)但是还没有弄清楚如何将其减去适当的边距或获取信封托盘 编辑工作代码(感谢icemanind为我指明了正确的方向。 C#有一个为各种打

我试着做一个非常简单的操作:

  • 获取本地打印机列表,让用户选择(获取此)

  • 选择信封托盘进行手动进纸

  • 在手动信封进纸打印机上按特定信封大小(4 1/8 x 9 1/2/03982)打印客户地址

  • 我没有上过System.Drawing.Printing课程的经验,所以请原谅我对这个话题的无知

    我在玩弄下面找到的代码,我一直在玩:
    Rectangle(20、20、200等)
    但是还没有弄清楚如何将其减去适当的边距或获取信封托盘

    编辑工作代码(感谢icemanind为我指明了正确的方向。 C#有一个为各种打印介质定义的枚举。其中一个是
    ManualFeed
    ,它被描述为
    ManualFeed envelope
    。您应该能够将属性设置为
    6
    ,这是
    ManualFeed


    设置后,您不必担心将其缩小到合适的大小。它应该会自动做到这一点。

    尝试PrinterSettings.PaperSizes属性使用PageSetupDialog类使其具有交互性和直观性。
       //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));
                }
        }