要求:可设置纸型(如:A4,A3,B4,B5),和自定义纸型。
重点在于自定义纸型,打印机不在默认纸型下,可打印代码设置的纸型。
如果已知打印纸型的长和宽,如何打印?用什么控件要写明白。
请多写注释!关于打印的类,偶实在是迷糊的很。
由于偶从来没学过打印,特请各位大虾帮忙。
      

解决方案 »

  1.   

    绝对定位打印如何? C# 逐行驱动打印
    http://blog.csdn.net/cnming/archive/2008/03/22/2204496.aspx
      

  2.   

    http://blog.csdn.net/cnming/archive/2008/03/22/2204496.aspx
      

  3.   

    这是我工作中写过的一个类。你可以对照参考一下。
    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    using System.Drawing;
    using System.Collections;
    using System.Data;
    using System.Text;
    namespace PrintText.Method
    {
        class Print
        {
            private static StringFormat StrFormat;
            private static StringFormat StrFormatComboBox;
            private static string PrintTitle = "";
            private static System.Drawing.Printing.PrintDocument printDoc = new System.Drawing.Printing.PrintDocument();        private static TextBox textBox1;
            private static TextBox textBox2;
            private static Label label1;
            private static Label label2;
            public static void Pint_test(Panel Pane)
            {
                PrintPreviewDialog textPint;
                try
                {
                    label1 = (Label)Pane.Controls.Find("label1", true)[0];
                    textBox1 = (TextBox)Pane.Controls.Find("textBox1", true)[0];//姓名                label2 = (Label)Pane.Controls.Find("label2", true)[0];
                    textBox2 = (TextBox)Pane.Controls.Find("textBox2", true)[0];//性别                textPint = new PrintPreviewDialog();
                    textPint.Document = printDoc;
                    printDoc.BeginPrint += new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
                    printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
                    if (textPint.ShowDialog() != DialogResult.OK)
                    {
                        printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
                        printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
                        return;
                    }
                    printDoc.Print();
                    printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
                    printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {            }        }        private static void PrintDoc_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
            {
                try
                {
                    StrFormat = new StringFormat();
                    StrFormat.Alignment = StringAlignment.Near;//布局对齐
                    StrFormat.LineAlignment = StringAlignment.Center;//居中对齐
                    StrFormat.Trimming = StringTrimming.EllipsisCharacter;//指定如何在不完全适合布局形状的字符串中修整字符
                    StrFormatComboBox = new StringFormat();
                    StrFormatComboBox.LineAlignment = StringAlignment.Center;
                    StrFormatComboBox.FormatFlags = StringFormatFlags.NoWrap;
                    StrFormatComboBox.Trimming = StringTrimming.EllipsisCharacter;            }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }        private static void PrintDoc_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
            {            //姓名
                e.Graphics.DrawRectangle(Pens.Black, 60, 100, 700, 200);
                String A = "姓名";
                e.Graphics.DrawString(A, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 120, 120);            e.Graphics.DrawRectangle(Pens.Black, 60, 100, 150, 40);
                String B = "";
                e.Graphics.DrawString(B, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 60, 150);            e.Graphics.DrawRectangle(Pens.Black, 60, 140, 150, 40);
                String C = textBox1.Text;
                e.Graphics.DrawString(C, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 100, 150);            e.Graphics.DrawRectangle(Pens.Black, 60, 180, 150, 40);
                String D = "";
                e.Graphics.DrawString(D, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 60, 150);
                e.Graphics.DrawRectangle(Pens.Black, 60, 220, 150, 40);
                String E = "";
                e.Graphics.DrawString(E, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 60, 150);
                e.Graphics.DrawRectangle(Pens.Black, 60, 260, 150, 40);
                String F = "";
                e.Graphics.DrawString(F, new Font(textBox1.Font, FontStyle.Bold), Brushes.Black, 60, 150);
            }
        }
    }
      

  4.   

    cnming  !比较 强悍 看看BLOG里面的文章
      

  5.   


    private void initDialog()
            {
                //新建打印页面
                printDocument = new PrintDocument();            //初始化标题格式
                titleFormat = new StringFormat();
                titleFormat.Alignment = StringAlignment.Center;
                titleFormat.LineAlignment = StringAlignment.Center;
                titleFormat.Trimming = StringTrimming.EllipsisCharacter;            //初始化数据区格式
                dataFormat = new StringFormat();
                dataFormat.Alignment = StringAlignment.Center;
                dataFormat.LineAlignment = StringAlignment.Far;
                dataFormat.Trimming = StringTrimming.EllipsisCharacter;            //设置页面格式
                pageSetupDialog = new PageSetupDialog();
                pageSetupDialog.AllowOrientation = true;                        //允许横向
                pageSetupDialog.Document = printDocument;                       //绑定页面
                if (this.title.IndexOf(CommonString.strAlTableKey) > 0)
                {
                    pageSetupDialog.Document.DefaultPageSettings.Landscape = false;  //设置打印为纵向;                normalFont = new Font("NSimSun", 9);
                    sumFont = new Font("NSimSun", 9);
                }
                else
                {
                    pageSetupDialog.Document.DefaultPageSettings.Landscape = true;  //设置打印为横向
                    pageSetupDialog.PageSettings.Margins.Left = 20;
                    pageSetupDialog.PageSettings.Margins.Top = 50;
                    normalFont = new Font("NSimSun", 6);
                    sumFont = new Font("NSimSun", 6);
                }            printPreviewDialog = new PrintPreviewDialog();
                printPreviewDialog.Document = printDocument;
                printPreviewDialog.Height = 600;
                printPreviewDialog.Width = 800;
                printPreviewDialog.ClientSize = new System.Drawing.Size(1500, 1000);  //纸张1169, 827
                printPreviewDialog.PrintPreviewControl.Zoom = 1;            //初始页
                curPage = 1;
                //初始打印行
                RowPos = 0;
                
                if(this.dgv.Rows.Count < 10)
                {
                    rowGap = rowGap * 3 / 2;
                    sumRowGap = sumRowGap * 3 / 2;
                }            //初始化列宽度
                initColHeightInfo(0);
            }看看是否有帮助吧
      

  6.   

    上面,这里是我打印dgv的初始化代码片断,设置的数字刚被我随手改了,
    你结合自己的情况,其中pageSetupDialog.ShowDialog();可以看到都可以设置什么,自己再研究下就OK了
      

  7.   

    三个成员private PrintDocument printDocument;
            private PageSetupDialog pageSetupDialog;
            private PrintPreviewDialog printPreviewDialog;
    你要设置的东西我想只能在PageSetupDialog 中设定了
      

  8.   

    PageSetupDialog 如何设置?
    是实例化以后在设置吗 ?
    这个对象的哪些属性是设置纸型的?
      

  9.   

    哦,我看错了,就是如何设置papersize?