winform打印问题.打印一图片,预览图片总是在左上角.如何调整居中.及其大小?
winform打印问题.打印一图片,预览图片总是在左上角.如何调整居中.及其大小?
------解决方案--------------------Winfrom 自带控制还是三方控件?
------解决方案--------------------
   private void button2_Click(object sender, EventArgs e)
       {
           PrintDocument _Docunment = new PrintDocument();
           _Docunment.PrintPage += new PrintPageEventHandler(_Docunment_PrintPage);
           PrintPreviewDialog _Dilaog = new PrintPreviewDialog();
           _Dilaog.Document = _Docunment;
           _Dilaog.ShowDialog();
       }
       void _Docunment_PrintPage(object sender, PrintPageEventArgs e)
       {
           Image _PrintImage =this.Icon.ToBitmap();
           int _X = (e.PageBounds.Width- _PrintImage.Width) / 2;
           int _Y = (e.PageBounds.Height - _PrintImage.Height) / 2;
           e.Graphics.DrawImage(_PrintImage, _X, _Y, _PrintImage.Width, _PrintImage.Height);
       }
------解决方案--------------------
如果根据比例调整大小 可以偷懒使用PictureBox
 void _Docunment_PrintPage(object sender, PrintPageEventArgs e)
       {
           Image _PrintImage =this.Icon.ToBitmap();
           PictureBox _PictureBox = new PictureBox();
           _PictureBox.BackColor = Color.White;
           _PictureBox.Size = e.PageBounds.Size;
           _PictureBox.SizeMode = PictureBoxSizeMode.Zoom;
           _PictureBox.Image = _PrintImage;
           Bitmap _Bitmap = new Bitmap(e.PageBounds.Width, e.PageBounds.Height);
           _PictureBox.DrawToBitmap(_Bitmap, new Rectangle(0, 0, _Bitmap.Width, _Bitmap.Height));          
           e.Graphics.DrawImage(_Bitmap,0,0,_Bitmap.Width,_Bitmap.Height);
       }