【发布时间】:2016-05-19 20:51:37
【问题描述】:
我正在使用 WinForms。在我的表单中,我有一个图片框和一个打印按钮。有没有办法让我加载到图片框中的图像始终位于打印预览窗口的中心?下图显示了我的表单和打印预览屏幕中未居中的图像。
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Image = new Bitmap(@"C:\Users\Nav\Pictures\Test_Image.png");
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(pictureBox1.Image,50,50);
}
private void Btn_Print_Click(object sender, EventArgs e)
{
printPreviewDialog1.Document = printDocument1;
printPreviewDialog1.ShowDialog();
}
【问题讨论】:
-
而不是绝对/固定坐标(
50, 50),计算中心 -
您没有在文档中心绘制图像。你在
(50,50)绘制它 -
我明白了,所以我猜没有像 e.image.center 这样的方式来做到这一点。
-
如果我使用
e.Graphics.DrawImage(pictureBox1.Image, e.MarginBounds);,它会给它一个边距,但它也会拉伸图像。
标签: c# .net image winforms printing