打印与打印在 C# 中打印预览位图和带有文本的标签

发布于 2024-10-04 06:42:40 字数 656 浏览 2 评论 0原文

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

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。

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

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

I have made a function in my program that will print off bitmaps and a image from a picturebox, but now want to print a label with text in it as well. This is my current code:

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);    
 }

My label is called ExtraNotes, and my picturebox is capturebox.

I want to be able to print both of these with the label contents either to the side or below the image, i don't mind.

I also want to be able to print preview this using a print preview dialog of which i don't know how to make show this, i can get it to open but not show the things i want it to.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甚是思念 2024-10-11 06:42:40

我认为您的意思是这样做:

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);    
 }

您可以更改文本所在位置的坐标。

I think you meant to do this:

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);    
 }

You can change the corrdinates of where you want the text to go.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文