Hope I can get some help with my problem, might be a simple fix. I'm trying to create a custom chart control (inheriting from the Chart class). In my constructor, I'm adding a ChartArea and Legend. Everything is fine when I add the control to the form, but when I run it, I get an error in the form designer saying a chart area already exists with the same name as the one I added in the constructor. So my problem is that the chart area is trying to be added a second time in the form designer generated code. I could remove this from the generated code but I wanted to see if there was an easier way to control it in my custom chart class. The constructor code for the chart is:
public MultiFunctionalGraph(DataForGraph dataA, DataForGraph dataB, DataForGraph dataC, DataForGraph dataD)
{
this.dataA = dataA;
this.dataB = dataB;
this.dataC = dataC;
this.dataD = dataD;
ChartArea chartArea = new ChartArea();
Legend legend = new Legend();
Axis xAxis = new Axis(chartArea, AxisName.X);
Axis yAxis = new Axis(chartArea, AxisName.Y);
chartArea.Name = "ChartArea";
chartArea.Visible = true;
this.ChartAreas.Add(chartArea);
legend.Name = "Legend";
this.Legends.Add(legend);
}
And I get this in the code generation in the designer:
this.Graph1 = Graph();
((System.ComponentModel.ISupportInitialize)(this.Graph1)).BeginInit();
// Graph1
//
this.Graph1.BackColor = System.Drawing.Color.Transparent;
chartArea1.AxisX.Interval = 5D;
chartArea1.AxisX.MajorGrid.Interval = 10D;
chartArea1.AxisX.MajorTickMark.Interval = 5D;
chartArea1.AxisY.LabelStyle.Interval = 500D;
chartArea1.AxisY.MajorGrid.Interval = 500D;
chartArea1.AxisY.MajorTickMark.Interval = 500D;
chartArea1.AxisY.MinorGrid.Interval = 500D;
chartArea1.AxisY.MinorTickMark.Interval = 500D;
chartArea1.CursorX.LineColor = System.Drawing.Color.LimeGreen;
chartArea1.CursorX.LineWidth = 2;
chartArea1.CursorY.LineColor = System.Drawing.Color.LimeGreen;
chartArea1.CursorY.LineWidth = 2;
chartArea1.Name = "ChartArea";
this.Graph1.ChartAreas.Add(chartArea1);
legend1.AutoFitMinFontSize = 5;
legend1.Name = "Legend";
legend1.TextWrapThreshold = 20;
this.Graph1.Legends.Add(legend1);
this.Graph1.Location = new System.Drawing.Point(46, 302);
this.Graph1.Name = "Graph1";
this.Graph1.Size = new System.Drawing.Size(569, 300);
this.Graph1.TabIndex = 7;
this.Graph1.Text = "Graph1";
So basically I have to stop generating the code to add the chart area in the designer. I think I can get it using the DesignerSerialize attribute somewhere but I could really use some help. Thank you!