0

我用 C# 开发了一个应用程序,我想在打印机中打印我的表单中的标签,而不是打印整个表单。我的四个标签是lblName, lblAge, lblAdd, lblEmail. 我只想打印这些标签而不是表格。有人可以帮我吗?谢谢!

无论如何,这是我单击按钮时要打印的代码。

private void btnPrint_Click(object sender, EventArgs e)
{         
    PaperSize pp = new PaperSize("MyReport", 718, 359);
    printForm1.PrinterSettings.DefaultPageSettings.PaperSize = pp;
    printForm1.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
  //printForm1.PrintAction = System.Drawing.Printing.PrintAction.PrintToPreview;
    printForm1.Print(this, PrintForm.PrintOption.CompatibleModeClientAreaOnly);

}
4

1 回答 1

1

您可以在此处找到您要查找的内容,将内容放入 Panel 控件并打印:Print Panel in Windows Form C#

这是我快速而肮脏的方法。如果您将所有内容都放在白色表格上,并且只想显示标签、打印和封闭表格,这将起作用。上面的可能会更好!

private void btnPrint_Click(object sender, EventArgs e)
{         
    PaperSize pp = new PaperSize("MyReport", 718, 359);
    printForm1.PrinterSettings.DefaultPageSettings.PaperSize = pp;
    printForm1.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);

    // Show the labels...
    lblAge.Visible = true;
    lblAdd.Visible = true;
    lblName.Visible = true;
    lblEmail.Visible = true;

    // ...Print them visible...
    printForm1.Print(this, PrintForm.PrintOption.CompatibleModeClientAreaOnly);

    // ...Then hide again
    lblAge.Visible = false;
    lblAdd.Visible = false;
    lblName.Visible = false;
    lblEmail.Visible = false;

}
于 2013-05-20T10:23:23.410 回答