728x90
728x170

1.       

        private Bitmap ConvertDataGridViewToBmp1(DataGridView dg)
        {
            int height = dg.Height;
            dg.Height = dg.RowCount * dg.RowTemplate.Height;

            Bitmap bitmap = new Bitmap(dg.Width, dg.Height);
            dg.DrawToBitmap(bitmap, new Rectangle(0, 0, dg.Width, dg.Height));

            dg.Height = height;

            return bitmap;
        }

 

2.

        [DllImport("gdi32.dll", ExactSpelling = true, CharSet = CharSet.Auto, SetLastError = true)]
        private static extern bool BitBlt(IntPtr pHdc, int iX, int iY, int iWidth, int iHeight, IntPtr pHdcSource, int iXSource, int iYSource, System.Int32 dw);
        private const int src = 0xCC0020;

        private Bitmap ConvertDataGridViewToBmp2(DataGridView dg)
        {
            this.dataGridView.ColumnHeadersVisible = false;
            this.dataGridView.RowHeadersVisible = false;

            dg.Refresh();
            dg.Select();

            Graphics g = dg.CreateGraphics();
            Bitmap bitmap = new Bitmap(dg.ClientSize.Width, dg.ClientSize.Height, g);
            Graphics g = Graphics.FromImage(bitmap);
            IntPtr bitmapHoc = g.GetHdc();
            IntPtr gHoc = g.GetHdc();

            BitBlt(bitmapHoc, 0, 0, dg.ClientSize.Width, dg.ClientSize.Height, gHoc, 0, 0, src);

            g.ReleaseHdc(gHoc);

            g.ReleaseHdc(bitmapHoc);

            return bitmap;
        }

728x90
그리드형
Posted by kjun.kr
,