Пример #1
0
        private void printDoc_PrintPage(object sender, PrintPageEventArgs e)
        {
            System.Drawing.Rectangle bounds = System.Drawing.Rectangle.Empty;
            if (pageBounds)
            {
                bounds = e.PageBounds;
            }
            else
            {
                bounds = e.MarginBounds;
            }

            System.Drawing.Image tmp = (System.Drawing.Image)picture.Clone();
            if (stretch == Stretch.Fill)
            {
                tmp = picture.Resize(bounds.Width, bounds.Height);
            }
            else if (stretch == Stretch.Uniform)
            {
                tmp = picture.ResizeProportional(bounds.Width, bounds.Height);
            }

            int x = bounds.Left, y = bounds.Top;

            if (alignX == AlignmentX.Center)
            {
                x = bounds.Left + bounds.Width / 2 - tmp.Width / 2;
            }
            else if (alignX == AlignmentX.Right)
            {
                x = bounds.Left + bounds.Width - tmp.Width;
            }
            if (alignY == AlignmentY.Center)
            {
                y = bounds.Top + bounds.Height / 2 - tmp.Height / 2;
            }
            else if (alignY == AlignmentY.Bottom)
            {
                y = bounds.Top + bounds.Height - tmp.Height;
            }

            e.Graphics.DrawImage(tmp, new System.Drawing.Point(x, y));
        }