【发布时间】:2019-04-27 22:47:43
【问题描述】:
我需要将整个 DataGridView 保存为图像。
我在网上看到过一些帖子,但它对我不起作用。
到目前为止,我已经尝试了这两个链接:
DataGridView to Bimap 和 Save Image in folder。
我的意图是一旦按下按钮,DataGridView 将被转换为图像并自动保存到桌面。
我使用的代码会产生错误:
GDI+ 中发生一般错误
private void button1_Click(object sender, EventArgs e)
{
//Resize DataGridView to full height.
int height = dataGridView1.Height;
dataGridView1.Height = dataGridView1.RowCount * dataGridView1.RowTemplate.Height;
//Create a Bitmap and draw the DataGridView on it.
Bitmap bitmap = new Bitmap(this.dataGridView1.Width, this.dataGridView1.Height);
dataGridView1.DrawToBitmap(bitmap, new Rectangle(0, 0, this.dataGridView1.Width, this.dataGridView1.Height));
//Resize DataGridView back to original height.
dataGridView1.Height = height;
//Save the Bitmap to folder.
bitmap.Save(@"C:\\Desktop\\datagrid.jpg");
}
希望能得到一些帮助。谢谢!
【问题讨论】:
-
除了其他的注意事项之外,请注意,这仅在位图的两个维度都
标签: c# winforms datagridview graphics bitmap