【问题标题】:Printing a textbot text打印文本机器人文本
【发布时间】:2014-07-28 23:52:58
【问题描述】:

我正在尝试制作一个打印文本框全文的程序。当我将其生成为 pdf 以在打印之前查看页面时,某些文本丢失了。

这是我的代码:

private void Print_Click(object sender, EventArgs e)
{
    PrintDialog PD = new PrintDialog();
    PrintDocument PDoc = new PrintDocument();
    PD.Document = PDoc;

    PDoc.PrintPage += new PrintPageEventHandler(PDoc_PrintPage);

    DialogResult result = PD.ShowDialog();

    if (result == DialogResult.OK)
    {
        PDoc.Print();
    }

}

void PDoc_PrintPage(object sender, PrintPageEventArgs e)
{
    Graphics graph = e.Graphics;
    graph.DrawString(textBox1.Text, 
        new Font("Arial", 12), new SolidBrush(Color.Black), 10, 10);
}

这是正文(仅供测试):

hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello

hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello

hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello

这是文本框截图:

这是我得到的:

如您所见,缺少一些文本。我对打印不是很熟悉,所以我不知道如何解决这个问题。

【问题讨论】:

  • 不,我看不到缺少什么,因为我看不到应该打印的内容。
  • 所以你错过了一些你好?
  • 当您在调试器中检查textBox1.Text 时,它包含什么?
  • @HimBromBeere 是的,你好只是一个例子,问题出在任何文本中。
  • 在文本框中显示所有文本。

标签: c# printing textbox printdocument


【解决方案1】:

看来您的问题是您希望文本在打印时换行。看看这个之前的帖子:Automatically Word-Wrapping Text To A Print Page?

【讨论】:

    猜你喜欢
    • 2013-04-11
    • 1970-01-01
    • 2018-09-03
    • 2020-08-08
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多