我寫(復制)了一個小代碼來選擇一些影像檔案并每五分鐘列印一次。
列印時,影像不適合紙張。它更小或更大。所以我想將影像調整為 A4 頁面大小。我找不到任何屬性。
有沒有辦法做到這一點?
這是我的代碼:
private async void button1_Click(object btnSender, EventArgs e)
{
// Set the file dialog to filter for graphics files.
this.openFileDialog1.Filter =
"Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|"
"All files (*.*)|*.*";
// Allow the user to select multiple images.
this.openFileDialog1.Multiselect = true;
this.openFileDialog1.Title = "My Image Browser";
DialogResult dr = this.openFileDialog1.ShowDialog();
if (dr == DialogResult.OK)
{
// Read the files
foreach (string file in openFileDialog1.FileNames)
{
PrintDialog printDlg = new PrintDialog();
PrintDocument printDoc = new PrintDocument();
printDoc.DocumentName = "Print Document";
printDlg.Document = printDoc;
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
printDoc.DefaultPageSettings.Landscape = true;
printDoc.PrintPage = (sender, args) =>
{
Image i = Image.FromFile(file);
Point p = new Point(0, 0);
args.Graphics.DrawImage(i, p);
};
printDoc.Print();
await Task.Delay(300000);
}
Process.Start("shutdown.exe", "-s -t 00");
}
}
uj5u.com熱心網友回復:
您不需要定義點;
要將影像適合頁面只需使用args.Graphics.DrawImage(i, args.PageBounds);
而不是args.Graphics.DrawImage(i, p);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/476109.html
下一篇:過濾串列違反開閉原則
