Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I add new methods to a pointstyle object?

Using a scatterplot, I change each point's color (and shape) to reflect the range of the Y-value passed in. This is done with an override to the "draw" function (see below). Right now the Y-value ranges are "hardcoded" in the override. I would like to be able to dynamically change the range with a user entry at runtime.
I have tried adding a public function to my code which could be called to change the value of the range variable, but .NET does not recognize it. Can this, in fact, be done, or is there an alternate scheme to accomplish the same thing?

thanks.

Code (partial):
public class DynamicPointStyle : PointStyle

{


private rangeHigh = 5;
private rangeLow = 2;
public override void Draw(obj
ect context, PointStyleDrawArgs args)

{
double yValue = args.Y;
if (Math.Abs(yValue) > rangeHigh) //5dB
PointStyle.Plus.Draw(context, CreateArgs(args, Color.Red));

else if (Math.Abs(yValue) > rangeLow) //2dB
PointStyle.EmptyCircle.Draw(context, CreateArgs(args, Color.Yellow));

else
PointStyle.SolidCircle.Draw(context, CreateArgs(args, Color.Green));

}
??public void updateRange (double rHigh, double rLow)
{
rangeHigh = rHigh;
rangeLow = rLow;
}
}
0 Kudos
Message 1 of 3
(3,516 Views)
I'm not sure what you mean by ".NET does not recognize it." Did your code not compile at all? If so, which part did the compiler complain about? When you tried to call the method, what was the type of the reference that you were calling the method on? Could you please also post the code that uses this class and that demonstrates the error?

Without having seen the code, though, my first guess would be that you were trying to call the method on a PointStyle reference, but the method doesn't live on PointStyle, so that was generating an error. If this is the case, you would need to hold on to a reference to the DynamicPointStyle class and call the method via this reference. For example:

class TestForm : Form
{
private DynamicPointStyle dynamic
Style;

protected override void OnLoad(EventArgs e)
{
// Keep a reference to the dynamic style so you can access the method
// later.

dynamicStyle = new DynamicPointStyle();
plot1.PointStyle = dynamicStyle;
}

private void UpdatePointStyleRange(double low, double high)
{
// To update the range, call the method via the DynamicPointStyle
// reference instead of trying to call if via a PointStyle reference.

dynamicStyle.UpdateRange(low, high);
}
}

- Elton
Message 2 of 3
(3,516 Views)
Thanks, Elton. The reference to DynamicPointStyle, as you illustrated, did the trick.
0 Kudos
Message 3 of 3
(3,516 Views)