C# 跨越DataGridView的滚动条截图

方法到是很简单

先成一个PICTUREBOX 截个DataGridView的图 然后显示到PICTUREBOX里 覆盖到DataGridView上

然后设置DataGridView的大小 别为不显示状态 用DrawToBitmap的方法获取全部图形 然后释放资源.

使用方法

 

 

 GetDataGridView(dataGridView1).Save(@"C:/1.bmp");

 

 

 

方法内部

 

  /// <summary>
        /// DATAGRIDVIEW跨越滚动截图
        /// </summary>
        /// <param name="_View">DataGridView</param>
        /// <returns>图形</returns>
        private static Image GetDataGridView(DataGridView _View)
        {
            PictureBox _NewPictureBox = new PictureBox();
            _NewPictureBox.Size = _View.Size;
            _NewPictureBox.Location = _View.Location;
            Bitmap _ViewBmp = new Bitmap(_NewPictureBox.Width, _NewPictureBox.Height);
            _View.DrawToBitmap(_ViewBmp, new Rectangle(0, 0, _NewPictureBox.Width, _NewPictureBox.Height));
            _NewPictureBox.Image = _ViewBmp;          
            _View.Parent.Controls.Add(_NewPictureBox);

            _View.Visible = false;
            _View.AutoSize = true;

            Bitmap _NewBitmap =new Bitmap(_View.Width,_View.Height);

            _View.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _View.Width, _View.Height));

            _View.AutoSize = false;
            _View.Visible = true;

            _View.Parent.Controls.Remove(_NewPictureBox);
            _ViewBmp.Dispose();
            _NewPictureBox.Dispose();
            return _NewBitmap;
        }

你可能感兴趣的:(c,image,C#,图形)