RT。
if ( dataGridView1.SelectedRows != 1 )
{
    returnl;
}Bitmap bmp = new Bitmap(dataGridView1.Width, dataGridView1.CurrentRow.Height);// 怎样将当前行转换为图片 ,保存到bmp中呢? 谢谢

解决方案 »

  1.   

    比如 dataGridView1.DrawToBitmap 可以将dataGridView1保存为图片 ,但是我现在只想将选中的当前行保存为图片 。谢谢
      

  2.   

    看来高手都忙着养家糊口去了,那我有个法你可以试一下,用那个DrrawToBitmap()存在图片,如bmp1(说实话,这一步我怀疑够呛能行,你先一试吧,不行我再想招儿!!);然后用Bitmap类的Clone方法复制其中的一部分,具体由Rectangle的参数决定,为了取得有效的Rectangle,你应先计算选中行的坐标!
      

  3.   

    那只有载图了.
    以下方法你参照一下       public void GetImage()//载取屏幕特定位置
            {
                try
                {
                    PrintPreviewDialog ppvw = new PrintPreviewDialog();
                    i = new Bitmap(this.panelChart.Width, this.panelChart.Height);
                    Graphics g = Graphics.FromImage(i);
                    Point p = panelChart.PointToScreen(panelChart.Location);
                    g.CopyFromScreen(p.X / 2+5, p.Y - 12, 0, 0, new Size(this.panelChart.Width, this.panelChart.Height-5));
                    ppvw.Document = printDoc;
                    printDoc.DefaultPageSettings.Landscape = true;
                    printDoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
                    if (ppvw.ShowDialog() != DialogResult.OK)
                    {
                        printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
                        return;
                    }
                    printDoc.Print();
                    g.Dispose();
                }
                catch
                {}
            }
      

  4.   

      if (dataGridView1.SelectedRows.Count != 0)
                {
                    DataGridViewRow _Row = dataGridView1.SelectedRows[0];
                    dataGridView1.FirstDisplayedCell = _Row.Cells[0];
                    Rectangle _Rectangle = dataGridView1.GetRowDisplayRectangle(_Row.Index,false);
                    Rectangle _AllCount = dataGridView1.GetColumnDisplayRectangle(0, false);
                    for (int i = 0; i != dataGridView1.Columns.Count; i++)
                    {
                        _AllCount.X += dataGridView1.Columns[i].Width;
                    }
                    _Rectangle.Width = _AllCount.X;                int _Width = dataGridView1.Width;
                    dataGridView1.Width = _Rectangle.X + _Rectangle.Width;
                    _Row.Selected = false;
                    Bitmap _NewBitmap = new Bitmap(dataGridView1.Width, dataGridView1.Height);              
                    dataGridView1.DrawToBitmap(_NewBitmap, new Rectangle(0, 0, _NewBitmap.Width, _NewBitmap.Height));
                    _Row.Selected = true;
                    dataGridView1.Width = _Width;
                    this.BackgroundImage = _NewBitmap.Clone(_Rectangle,_NewBitmap.PixelFormat);
                }
      

  5.   

    Mark,说不定以后会遇到类似问题