RT。
if ( dataGridView1.SelectedRows != 1 )
{
returnl;
}Bitmap bmp = new Bitmap(dataGridView1.Width, dataGridView1.CurrentRow.Height);// 怎样将当前行转换为图片 ,保存到bmp中呢? 谢谢
if ( dataGridView1.SelectedRows != 1 )
{
returnl;
}Bitmap bmp = new Bitmap(dataGridView1.Width, dataGridView1.CurrentRow.Height);// 怎样将当前行转换为图片 ,保存到bmp中呢? 谢谢
以下方法你参照一下 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
{}
}
{
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);
}