如何克隆Microsoft图表控件? [英] How can I clone microsoft chart control?

查看:114
本文介绍了如何克隆Microsoft图表控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

克隆Microsoft Chart Control对象的推荐方法是什么?由于它是第三方库,因此无法使用此处提到的解决方案 a>,因为我无法将对象标记为可序列化。



最好,除非绝对不可能,否则我不想引入任何第三方控件来克隆图表。

解决方案

您不需要将其标记为可序列化,因为图表已经可以序列化了。 。查看此质谱图文档以获取更多信息



从这里,您可以将图表序列化为字符串,然后立即将字符串反序列化为图表对象的新实例。这将类似于克隆,其行为似乎就是您的问题中提到的答案。

EDIT


$ b $可能不是最有效的方法。 b

此代码未设置,但可以正常工作(对于完成此操作而言相当准确)

 图表1 =新图表(); 
//在此处输入图表构建代码
System.IO.MemoryStream myStream = new System.IO.MemoryStream();
Chart chart2 = new Chart();
chart1.Serializer.Save(myStream);
chart2.Serializer.Load(myStream);


What's the recommended way of cloning an object of Microsoft Chart Control? Because it is a third-party library, I can't use the solution mentioned here as I can't mark the object as serializable.

Preferably, I would not like to introduce any third party controls to clone the chart unless if it is absolutely impossible to do so without one.

解决方案

You should not need to mark it as serializable as the charts already have the ability to be serialized. Check out this MS Charts Documentation for more information

From here, you can serialize the chart into a string, then immediately deserialize the string into a new instance of the chart object. This would act similarly to cloning, and appears to be what the answer mentioned in your quesiton is doing. It is probably not the most efficient method for doing this, but it will work

EDIT

This code is unteseted but should work (Be fairly accurate for how to accomplish this)

Chart chart1 = new Chart();
//Enter your chart building code here
System.IO.MemoryStream myStream = new System.IO.MemoryStream();
Chart chart2 = new Chart();
chart1.Serializer.Save(myStream);
chart2.Serializer.Load(myStream);

这篇关于如何克隆Microsoft图表控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆