印刷プレビュー ダイアログの内容を印刷できますか? 私はこのコードを持っていますが、印刷プレビュー ダイアログにあるものを印刷しませんでした。つまり、ボンド紙全体 (8.5x11) を 1 つ使用すると、このコードはボンド紙の左上端に印刷されますが、それは私が望んでいることではありません。紙を小切手のサイズにカットしてから、プリンターの用紙トレイを縮小して、紙の正確なサイズ (小切手のサイズ) を入れる必要があります。これは可能ですか?
これは私のコードです:
Bitmap MemoryImage;
PrintDocument printdoc1 = new PrintDocument();
PrintPreviewDialog previewdlg = new PrintPreviewDialog();
Panel pannel = null;
public chequeLayout()
{
InitializeComponent();
//declare event handler for printing in constructor
printdoc1.PrintPage += new PrintPageEventHandler(printdoc1_PrintPage);
}
public void GetPrintArea(Panel pnl)
{
MemoryImage = new Bitmap(pnl.Width, pnl.Height);
Rectangle rect = new Rectangle(0, 0, pnl.Width, pnl.Height);
pnl.DrawToBitmap(MemoryImage, new Rectangle(0,0, pnl.Width, pnl.Height));
}
protected override void OnPaint(PaintEventArgs e)
{
if (MemoryImage != null)
{
e.Graphics.DrawImage(MemoryImage, 0,0);
base.OnPaint(e);
}
}
public void printdoc1_PrintPage(object sender, PrintPageEventArgs e)
{
Rectangle pagearea = e.PageBounds;
e.Graphics.RotateTransform(-90);
yPrintCoordinate = ((CentimeterToPixel(Convert.ToDouble(txtWidth.Text))) - (2 * (CentimeterToPixel(Convert.ToDouble(txtWidth.Text))))) - 32;
e.Graphics.DrawImage(MemoryImage, yPrintCoordinate, 0);
}
public void Print(Panel pnl)
{
pannel = pnl;
GetPrintArea(pnl);
printdoc1.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Cheque Size", CentimeterToPixel(Convert.ToDouble(heightSize)), (CentimeterToPixel(Convert.ToDouble(widthSize))));
previewdlg.Document = printdoc1;
previewdlg.ShowDialog();
}
int CentimeterToPixel(double Centimeter)
{
double pixel = -1;
using (Graphics g = this.CreateGraphics())
{
pixel = Centimeter * g.DpiY / 2.54d;
}
return (int)pixel;
}
private void btnPrint_Click(object sender, EventArgs e)
{
Print(panel1);
}