【问题标题】:Print & Print Preview a Bitmap plus a Label with Text in it in c#在 c# 中打印和打印预览位图和带有文本的标签
【发布时间】:2010-11-25 20:02:26
【问题描述】:

我在我的程序中创建了一个函数,可以从图片框中打印位图和图像,但现在还想打印一个带有文本的标签。这是我当前的代码:

private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
  if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  {
    printDocument1.Print();
  }
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
 {
   e.Graphics.DrawImage(capturebox.BackgroundImage, 0, 0);
   e.ToString(ExtraNotes.Text);
   e.Graphics.DrawImage(capturebox.Image, 0, 0);    
 }

我的标签叫做ExtraNotes,我的图片框是capturebox。

我希望能够将这两个标签内容打印到图像的侧面或下方,我不介意。

我还希望能够使用打印预览对话框来打印预览,我不知道如何让它显示这个,我可以让它打开但不显示我想要的东西。

【问题讨论】:

    标签: c# text printing picturebox print-preview


    【解决方案1】:

    我认为你的本意是:

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
     {
       e.Graphics.DrawImage(capturebox.BackgroundImage, 0, 0);
       e.DrawString(ExtraNotes.Text, SystemFonts.CaptionFont, Brushes.Black, 10, 10);
       e.Graphics.DrawImage(capturebox.Image, 0, 0);    
     }
    

    你可以改变你想要文本去哪里的坐标。

    【讨论】:

    • 这个还是报错printpageeventargs不包含drawstring的定义??
    • 别担心,我只需要制作 e.DrawString(ExtraNotes.Text, SystemFonts.CaptionFont, Brushes.Black, 10, 10); to e.Graphics.DrawString(ExtraNotes.Text, SystemFonts.CaptionFont, Brushes.Black, 10, 10);
    • 糟糕;忘记输入图形。
    猜你喜欢
    • 2011-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多