当前程序文件夹pic下有4张jpg图片文件,单击winform窗体上的"打印"按钮后想把这4张图片通过A4的纸打印出来,每一张图片打印一页,请教代码如何实现
解决方案 »
- 删除老版本的ocx,再添加新版本ocx文件的问题?
- .NET的种类
- 这段委托看不懂,谁能帮下忙?~
- [推荐源代码]可以进行文字搜索及替换的TextBox、RichTextBox、ListView和TreeView
- 在窗体上画一根凹下去的细线怎么做 ?
- 高分请教--读文件的时候中文读不出来怎么办?-在线等待
- C#求两条线段的角度
- 请问,如何实现控件大小随着窗口的最大化而变化,谢谢
- 图片绑定问题
- 大家帮帮我,急需sp1234的一段DEMO
- C#,winform,vs2005中,如何能用代码控制,使DateTimePicker自动弹出选择日期的面板?
- 请问一下DevExpress的 XtraReport,在打印的时候越界的问题。
打印按钮的代码:
C# codeCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/ private void button2_Click(object sender, EventArgs e)//执行打印 { PrintDialog MyPrintDg = new PrintDialog(); MyPrintDg.Document = printDocument1; if (MyPrintDg.ShowDialog() == DialogResult.OK) { try { printDocument1.Print(); } catch { //停止打印 printDocument1.PrintController.OnEndPrint(printDocument1, new System.Drawing.Printing.PrintEventArgs()); } } }
另外还要设置PrintPage事件:
C# codeCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/ private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawImage(pictureBox1.Image, 20, 20); }
FileStream fs = new FileStream(@"图片路径", FileMode.Open, FileAccess.Read);
fs.Read(input, 0, 100000);//设置打印页面
printDocument1.DefaultPageSettings.Landscape = true;//向打印页绘制图片
Image image = Image.FromStream(fs);
e.Graphics.DrawImage(image, 20, 20);//打印
printDocument1.Print();
private int printIndex=0; //打印索引,下面调用要用到
private int pageSize=3; //有三张图片要打印 private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
if (printIndex < pageSize)
{
e.Graphics.DrawImage(Image, 0, 0, photoWidth, photoHeight);
printIndex++; //如果打印的页数还不足3页,那么我要继续打印
if (printIndex < pageSize)
{
e.HasMorePages = true;
}
}
else
{
e.HasMorePages = false;
}
}