Nikpendar1
دوشنبه 17 اردیبهشت 1397, 11:49 صبح
دوستان عزیز سلام
با استفاده از کد زیر میتونم از فرم پرینت بگیرم و مشکلی نداره ولی پرینت رو گوشه صفحه میندازه و من میخوام پرینت در وسط صفحه قرار بگیره.
لطفا راهنمایی کنید.
کد پرینت فرم:
Bitmap memoryImage;
public void CaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
}
private void PrintButton_Click(object sender, EventArgs e)
{
CaptureScreen();
PrintDialog printDlg = new PrintDialog();
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
//Call ShowDialog
if (printDlg.ShowDialog() == DialogResult.OK)
{
printDocument2.PrinterSettings = printDlg.PrinterSettings;
printDocument2.Print();
}
}
private void printDocument2_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
با استفاده از کد زیر میتونم از فرم پرینت بگیرم و مشکلی نداره ولی پرینت رو گوشه صفحه میندازه و من میخوام پرینت در وسط صفحه قرار بگیره.
لطفا راهنمایی کنید.
کد پرینت فرم:
Bitmap memoryImage;
public void CaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
}
private void PrintButton_Click(object sender, EventArgs e)
{
CaptureScreen();
PrintDialog printDlg = new PrintDialog();
printDlg.AllowSelection = true;
printDlg.AllowSomePages = true;
//Call ShowDialog
if (printDlg.ShowDialog() == DialogResult.OK)
{
printDocument2.PrinterSettings = printDlg.PrinterSettings;
printDocument2.Print();
}
}
private void printDocument2_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}