Hi,
How can I print an while preserving its aspect ratio. Currently I am using the code below.
This prints perfectly except that it losses its aspect ratio. I would be grateful if someone could kindly help me or tell me what to modify?
Thanks in advance:)
How can I print an while preserving its aspect ratio. Currently I am using the code below.
Code:
private void PrintClicked(object sender, EventArgs e)
{
PrintDocument doc = new PrintDocument();
doc.PrintPage += this.Doc_PrintPage;
PrintDialog dlgSettings = new PrintDialog();
dlgSettings.Document = doc;
if (dlgSettings.ShowDialog() == DialogResult.OK)
{
doc.Print();
}
}
private void Doc_PrintPage(object sender, PrintPageEventArgs e)
{
Bitmap img = GetScreenAsImage(); // Get the image of screen
PageSettings ps = e.PageSettings;
Rectangle tes = ps.Bounds;
int x = tes.Location.X;
int y = tes.Location.Y;
//Reduce width and height by 50 as otherwise the image is outside printable area.
int width = tes.Size.Width - 50;
int height = tes.Size.Height - 50 ;
Rectangle rect = new Rectangle(x, y, width, height);
e.Graphics.DrawImage(img, rect);
}
Thanks in advance:)
Comment