任何人都可以帮助我使用 c#(Visual Studio .NET 2005 或 2008)打印 flowlayoutpanel 中的所有 10 个图像
我不知道该怎么做?
任何人都可以帮助我使用 c#(Visual Studio .NET 2005 或 2008)打印 flowlayoutpanel 中的所有 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 中验证控件类型、在开始打印之前验证图像数量、缩放图像和其他一些东西。