You can use the serializer to clone objects or copy state from one chart object to another. The following code creates a chart that is identical to the first chart in the Charts collection:
| C# |
Copy Code
|
|---|---|
NControlSerializer serializer = chartControl.Serializer; NChart chart = chartControl.Charts[0]; // save the chart to memory stream MemoryStream memoryStream = new MemoryStream(); serializer.SaveToStream(chart, memoryStream, PersistencyFormat.Binary, null); // go back to the beginning of the stream memoryStream.Position = 0; NChart chart2 = (NChart)serializer.LoadFromStream(typeof(NChart), memoryStream, PersistencyFormat.Binary, null); |
|
| Visual Basic |
Copy Code
|
|---|---|
Dim serializer As NControlSerializer = chartControl.Serializer Dim chart As NChart = chartControl.Charts(0) ' save the chart to memory stream Dim memoryStream As New MemoryStream serializer.SaveToStream(chart, memoryStream, PersistencyFormat.Binary, Nothing) ' go back to the beginning of the stream memoryStream.Position = 0 Dim chart2 As NChart = CType(serializer.LoadFromStream(GetType(NChart), memoryStream, PersistencyFormat.Binary, Nothing), NChart) |
|
Notice that you have to reset the stream position after you serialize the object:
| C# |
Copy Code
|
|---|---|
// go back to the beginning of the stream
memoryStream.Position = 0;
|
|
| Visual Basic |
Copy Code
|
|---|---|
' go back to the beginning of the stream
memoryStream.Position = 0
|
|