如何使用c#打印flowlayoutpanel的所有图像

发布于 2024-10-15 23:46:10 字数 105 浏览 2 评论 0原文

任何人都可以帮助我使用 c#(Visual Studio .NET 2005 或 2008)打印 flowlayoutpanel 中的所有 10 个图像,

我不知道如何执行此操作?

Can anyone help me to print all 10 images which are in a flowlayoutpanel using c# (Visual Studio .NET 2005 or 2008)

I do not have any idea how to do this?

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

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

发布评论

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

评论(1

来世叙缘 2024-10-22 23:46:10

如果您询问 WinForms FlowLayoutPanel 并且您正在使用 PictureBox-es 来显示图像,那么您可以尝试如下操作:

private int imagesToPrintCount;

private void PrintAllImages()
{
    imagesToPrintCount = flowLayoutPanel1.Controls.Count;
    PrintDocument doc = new PrintDocument();
    doc.PrintPage += Document_PrintPage;
    PrintDialog dialog = new PrintDialog();
    dialog.Document = doc;

    if (dialog.ShowDialog() == DialogResult.OK)
        doc.Print();      
}

private void Document_PrintPage(object sender, PrintPageEventArgs e)
{
    e.Graphics.DrawImage(GetNextImage(), e.MarginBounds);
    e.HasMorePages = imagesToPrintCount > 0;
}

private Image GetNextImage()
{
    PictureBox pictureBox = (PictureBox)flowLayoutPanel1.Controls[flowLayoutPanel1.Controls.Count - imagesToPrintCount];
    imagesToPrintCount--;
    return pictureBox.Image;
}

请记住,您可能需要验证 FlowLayoutPanel 中的控件类型、在开始打印之前验证图像计数、缩放图像等其他的东西。

If you asking about WinForms FlowLayoutPanel and you are using PictureBox-es to display images, then you can try something like this:

private int imagesToPrintCount;

private void PrintAllImages()
{
    imagesToPrintCount = flowLayoutPanel1.Controls.Count;
    PrintDocument doc = new PrintDocument();
    doc.PrintPage += Document_PrintPage;
    PrintDialog dialog = new PrintDialog();
    dialog.Document = doc;

    if (dialog.ShowDialog() == DialogResult.OK)
        doc.Print();      
}

private void Document_PrintPage(object sender, PrintPageEventArgs e)
{
    e.Graphics.DrawImage(GetNextImage(), e.MarginBounds);
    e.HasMorePages = imagesToPrintCount > 0;
}

private Image GetNextImage()
{
    PictureBox pictureBox = (PictureBox)flowLayoutPanel1.Controls[flowLayoutPanel1.Controls.Count - imagesToPrintCount];
    imagesToPrintCount--;
    return pictureBox.Image;
}

Keep in mind that you might need to verify control types in FlowLayoutPanel, verify images count before starting printing, scale images and some other stuff.

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