在C#中打印表单 [英] Print the form in C#

查看:348
本文介绍了在C#中打印表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿朋友

我打印我的表格页面本身就遇到了麻烦

请帮帮我这里是表格代码

我之前是使用其他代码质量无需打印

Hey Friends
I print my form page itself got into trouble
Please, help me here is the form code
I was previously using another code quality is not necessary to print

        private string filname;
        private StreamReader strtop;
        private Font font;

private void button3_Click(object sender, EventArgs e)
        {
            PrintDocument printduc = new PrintDocument();
            printduc.DocumentName = "Print";
            printDialog1.AllowPrintToFile = false;
            printDialog1.AllowSelection = false;
            printDialog1.AllowSomePages = false;

            printDialog1.Document = printduc;
            if (printDialog1.ShowDialog() == DialogResult.OK)
            {
                strtop = new StreamReader(filname);
                font = new Font("Arial", 13);
                printduc.PrinterSettings = printDialog1.PrinterSettings;
                printduc.PrintPage += new PrintPageEventHandler(prtPage);
                printduc.Print();
                strtop.Close();
                strtop = null;
            }
        }
        private void prtPage(object sender, PrintPageEventArgs e)
        {
            float sngLinesPerpage = 0;
            float sngVerPos = 0;
            int intLinCoun = 0;
            float sngLeftM = 0;
            float sngTopMost = 0;
            string strLine;
            sngLinesPerpage = e.MarginBounds.Height / font.GetHeight(e.Graphics);
            strLine = strtop.ReadLine();
            while ((intLinCoun < sngLinesPerpage) && (strLine != null))
            {
                sngVerPos = sngTopMost + (intLinCoun * font.GetHeight(e.Graphics));
                e.Graphics.DrawString(strLine, font, Brushes.Black, sngLeftM, sngVerPos, new StringFormat());
                intLinCoun = intLinCoun + 1;
                if (intLinCoun < sngLinesPerpage)
                {
                    strLine = strtop.ReadLine();
                }
            }
            if (strLine != null)
            {
                e.HasMorePages = true;
            }
            else
            {
                e.HasMorePages = false;
            }
        }

推荐答案

请看我过去的回答:如何从C#中打印另一种形式的窗体 [< a href =http://www.codeproject.com/Answers/859029/How-can-I-print-a-windows-form-from-another-form-itarget =_ blanktitle =新窗口> ^ ]。



-SA
Please see my past answer: How can I print a windows form from another form in C#[^].

—SA


这篇关于在C#中打印表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆