“打印对话框"将不打印文本(需要专家帮助) [英] Print Dialog will not print text (expert help needed)

查看:119
本文介绍了“打印对话框"将不打印文本(需要专家帮助)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我遇到了一个可能很简单的问题.在打印对话框中,当我按打印"时,应用程序确实向打印机发送了一条消息以进行打印,但是它不打印任何文本!
我在工具栏中有一个名为打印"的按钮,当我单击它时,我希望打印机打印富文本框中的内容.我将其命名为"telep".
首先,我使用clarify语句:

Hello everybody, I have run into a probably simple problem. In the printdialog, when i press ''Print'' the application does send a message to the printer to print, BUT it does not print any text!
I have a button in the toolbar called ''print'' and when i click it i want my printer to print what is in my rich text box. i named it ''telep''.
first i use the declare statement:

private System.Drawing.Printing.PrintDocument docToPrint =
        new System.Drawing.Printing.PrintDocument();



然后我在打印按钮中有实际的代码:



then i have the actual code inside the print button:

private void printToolStripMenuItem_Click(object sender, EventArgs e)
        {
            printDialog1.AllowSomePages = true;
            // Show the help button.
            printDialog1.ShowHelp = true;
            printDialog1.Document = docToPrint;
            DialogResult result = printDialog1.ShowDialog();
            // If the result is OK then print the document.
            if (result == DialogResult.OK)
            {
                docToPrint.Print();
            }
        }



现在是详细信息:



and now the details:

private void document_PrintPage(object sender,
       System.Drawing.Printing.PrintPageEventArgs e)
       {
           string text = "In document_PrintPage method.";
           System.Drawing.Font printFont = new System.Drawing.Font
               ("Arial", 35, System.Drawing.FontStyle.Regular);
           e.Graphics.DrawString(text, printFont,
               System.Drawing.Brushes.Black, 10, 10);
       }



感谢所有帮助!



All help is appreciated!

推荐答案

好,您的方法document_PrintPage不在任何地方使用.它的论据表明应该向打印流提供数据(这是使用Graphics的唯一位置),并提供可以打印的文本数据).如果您将其注释掉,您的代码仍将编译,对吗?那么您希望打印什么?

可能您是想使用此方法来设置PringPage事件?这样,您在哪里设置事件处理程序?可能是:

OK, your method document_PrintPage is not used anywhere. Its argument suggests it''s supposed to supply data to printing stream (this is the only place where Graphics is used) and your text data you could print is supplied). If you comment it out, you code will still compile, right? What would you expect to be printed then?

Probably you meant to use this method to set up PringPage event? It so, where do you setup the event handler? It could be:

docToPrint.PrintPage += new (document_PrintPage);



请检查易于理解的Microsoft示例: http://msdn. microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx [



Please check the Microsoft sample, which is easy to understand: http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

—SA


这篇关于“打印对话框"将不打印文本(需要专家帮助)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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