ColorBand tool code issue
Posted: Thu Apr 17, 2008 6:33 pm
Found in the TeeChart for .NET [04 APR 2008] RELEASE 3.2.3016.15520/1/2
That the code for the ColorBand tool had been modified. The change caused my code to throw an Null Reference exception at run time. The fix was pretty straight forward but I thought I would share it in case anyone else ran across the same problem.
My old code that worked fine prior to this latest release looked like:
The above code would throw the Null Reference Exception when trying to assign to the ColorBand.Axis property.
The fix was to make sure the Chart property is set either by doing it in the constructor of the ColorBand or via the ColorBand.Chart property.
So the fix looked like this:
That the code for the ColorBand tool had been modified. The change caused my code to throw an Null Reference exception at run time. The fix was pretty straight forward but I thought I would share it in case anyone else ran across the same problem.
My old code that worked fine prior to this latest release looked like:
Code: Select all
ColorBand colorband = new ColorBand();
colorband.Axis = tChart1.Axes.Left;
colorband.Brush.Color = System.Drawing.Color.Red;
colorband.Brush.Solid = true;
colorband.DrawBehind = true;
colorband.End = 300;
colorband.ResizeEnd = false;
colorband.ResizeStart = false;
colorband.Start = 250;
colorband.Pen.Visible = false; // hides the edge lines
colorband.Transparency = 50;
tChart1.Tools.Add(colorband);
The fix was to make sure the Chart property is set either by doing it in the constructor of the ColorBand or via the ColorBand.Chart property.
So the fix looked like this:
Code: Select all
ColorBand colorband = new ColorBand(tChart1.Chart;); // <- changed line
colorband.Axis = tChart1.Axes.Left;
colorband.Brush.Color = System.Drawing.Color.Red;
colorband.Brush.Solid = true;
colorband.DrawBehind = true;
colorband.End = 300;
colorband.ResizeEnd = false;
colorband.ResizeStart = false;
colorband.Start = 250;
colorband.Pen.Visible = false; // hides the edge lines
colorband.Transparency = 50;
tChart1.Tools.Add(colorband);