WinForm图表控件:将图表保存到文件时更改图表的大小
使用源代码中的方法 Chart.SaveImage()
时,有没有办法更改图表的大小?
目前,我发现设置图表大小的唯一方法是调整图表控件(System.Windows.Forms.DataVisualization.Charting.Chart
)所在窗体的大小。我可以显式设置其宽度和高度吗?尝试更改 Chart.Size
、Chart.Width
或 Chart.Size
不起作用。
is there a way to change size of chart when using method Chart.SaveImage()
from the source code?
Right now the only way I found to set the size of chart, is resize the form on which chart control (System.Windows.Forms.DataVisualization.Charting.Chart
) sits. Can I explicit set its width and height? Trying to change Chart.Size
, Chart.Width
or Chart.Size
doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的。解决方案非常明显,我三天都找不到它 - 我设置了
Chart.Dock = DockStyle.Fill
,因此更改Size
属性不会产生影响。将其修改为 DockStyle.None 后,我可以更改图表的大小并(最后!)以适当的宽度和高度保存它。All right. The solution was so obvious that I couldn't found it thou 3 days - I had setted
Chart.Dock = DockStyle.Fill
, so changingSize
property doesn't affect. After modified it toDockStyle.None
I could change chart's size and (finally!) save it with appropriative width and height.您可以通过重新定义图表的 Size 属性来定义它:
You can define it by redefining the Size property of the chart :
您可能必须将其保存到内存流,然后使用 Image 类更改尺寸,然后将其保存到文件。
You'll probably have to save it to a memory stream, then use the Image class to change dimensions and then save it to file.