How do I programmatically add pens to a trend window?

The following two (2) examples are for WinForm and WPF applications on how to add pens to a trend window during runtime programmatically.


WinForm:

Dim NewPen As OPCTrendControl.ClassPen

Dim NewPens As OPCTrendControl.ClassPen()

ReDim NewPens(2)

If NetworkPath = “””” Then

NewPen = New OPCTrendControl.ClassPen(NetworkPath + “”Ramp.Value””, “”localhost””)

Else

NewPen = New OPCTrendControl.ClassPen(NetworkPath + “”Ramp.Value””, NetworkNode)

End If

NewPen.LineBorderColor = Color.Blue

NewPen.LineFillColor = Color.Blue

NewPen.Description = “Ramp”

NewPen.LineStyle = OPCTrendControl.ClassPen.LineStyleTypes.Ellipsoid

NewPens(0) = NewPen



If NetworkPath = “” Then

NewPen = New OPCTrendControl.ClassPen(NetworkPath + “”Sine.Value””, “”localhost””)

Else

NewPen = New OPCTrendControl.ClassPen(NetworkPath + “”Sine.Value””, NetworkNode)

End If



NewPen.LineBorderColor = Color.Red

NewPen.LineFillColor = Color.Red

NewPen.Description = “Sine”

NewPen.YAxisRangeHigh = 1

NewPen.YAxisRangeLow = -1

NewPen.LineStyle = OPCTrendControl.ClassPen.LineStyleTypes.Tube

NewPens(1) = NewPen



If NetworkPath = “” Then

NewPen = New OPCTrendControl.ClassPen(NetworkPath + “”Random.Value””, “”localhost””)

Else

NewPen = New OPCTrendControl.ClassPen(NetworkPath + “”Random.Value””, NetworkNode)

End If



NewPen.LineBorderColor = Color.Green

NewPen.LineFillColor = Color.Green

NewPen.Description = “Random”

NewPen.MarkerFillColor = Color.Green

NewPen.MarkerStyle = OPCTrendControl.ClassPen.MarkerStyleTypes.Sphere

NewPen.MarkerSize = 20

NewPens(2) = NewPen



frmTrend.OpcTrendControl1.Pens = NewPens



WPF:



VB

Dim Pens As New OPCWPFDashboard.PensList

Dim NewPen As New OPCTrendControl.ClassPen



‘Add Ramp Pen

NewPen = New OPCTrendControl.ClassPen(“Ramp.Value”, “localhost”)

NewPen.Units = “”MGD””

NewPen.YAxisRangeHigh = 2

NewPen.LineStyle = OPCTrendControl.ClassPen.LineStyleTypes.Line

NewPen.Description = “Ramp Value”

Pens.Add(NewPen)



‘Add Random

NewPen = New OPCTrendControl.ClassPen(“Random.Value”, “localhost”)

NewPen.Units = “NTU”

NewPen.Description = “Random Pen”

Pens.Add(NewPen)

OPCWPFTrend1.Pens = Pens



C#

OPCWPFDashboard.PensList Pens = new OPCWPFDashboard.PensList();

OPCTrendControl.ClassPen NewPen = new OPCTrendControl.ClassPen();



//Add Ramp Pen

NewPen = new OPCTrendControl.ClassPen(“Ramp.Value”, “localhost”);

NewPen.Units = “MGD”;

NewPen.YAxisRangeHigh = 2;

NewPen.LineStyle = OPCTrendControl.ClassPen.LineStyleTypes.Line;

NewPen.Description = “Ramp Value”;

Pens.Add(NewPen);



//Add Random

NewPen = new OPCTrendControl.ClassPen(“Random.Value”, “localhost”);

NewPen.Units = “NTU”;

NewPen.Description = “Random Pen”;

Pens.Add(NewPen);

OPCWPFTrend1.Pens = Pens

<< View All FAQs
<< View All Troubleshooting Topics