使用SaveFileDialog保存图表的图像

时间:2017-03-29 15:08:01

标签: c# charts savefiledialog

点击按钮,我的程序会捕获图表的截图,标题为chartMain。代码如下:

private void buttonScreenshot_Click(object sender, EventArgs e)
{
    this.chartMain.SaveImage("C:/capture.png", ChartImageFormat.Png);
}

但是,这不允许用户指定保存位置,所以我想知道如何实现SaveFileDialog以允许用户选择保存位置。

有人可以指出我正确的方向,因为我目前卡住了。

提前谢谢。

2 个答案:

答案 0 :(得分:2)

一个简单的例子,根据您的需要进行修改(我会查看this页面):

var save = new SaveFileDialog();
save.Filter = "PNG files (*.png)|*.txt|All files (*.*)|*.*";
if(save.ShowDialog() == DialogResult.OK)
{
    this.chartMain.SaveImage(save.FileName, ChartImageFormat.Png);
} 

答案 1 :(得分:1)

这应该照顾你:

SaveFileDialog dialog = new SaveFileDialog();
if (dialog.ShowDialog() == DialogResult.OK)
{
   this.chartMain.SaveImage(dialog.FileName, ChartImageFormat.Png);
}