.NET Control: Create new Components

About this task

The Generic ActiveX Wrapper and other modules in the CimEdit .NET feature support hosting and interfacing with any WPF and WinForms controls, As a result, you can use third-party controls or create your own controls based on any .NET Framework WPF or WinForms control types.

Note: If you are using a third party control this procedure can be omitted.

Procedure

  1. Create a folder in the..\<CIMPLICITY Installation>\exe\DotNet Components directory.

    Example

    ..\Proficy\Proficy CIMPLICITY\exe\DotNet Components\My Samples

  2. Do the following.
    1. Use a text editor (e.g. Notepad) to write following code as a C# source file.
    2. Name the file TrendChart.cs.
    3. Save the file in your My Samples folder.
    using System;
    using System.Drawing;
    using System.Windows.Forms.DataVisualization.Charting;
    namespace ChartControls
    {
        public class TrendChart : Chart
        {
            private double _value;
            private ChartArea _area;
            private Series _series;
            private Title _title;
            public TrendChart()
            {
                BackColor = Color.Silver;
                BorderSkin.SkinStyle = BorderSkinStyle.FrameThin5;
                _title = Titles.Add("Trend Chart");
                _title.Font = new Font("Arial", 10, FontStyle.Bold);
                _area = ChartAreas.Add("area0");
                _area.AxisX.LabelStyle.Format = "hh:mm:ss";
                _area.AxisX.LabelStyle.Interval = 5;
                _area.AxisX.LabelStyle.IntervalType = DateTimeIntervalType.Seconds;
                _area.AxisX.MajorGrid.Interval = 5;
                _area.AxisX.MajorGrid.IntervalType = DateTimeIntervalType.Seconds;
                _area.BackColor = Color.Orange;
                _area.BackGradientStyle = GradientStyle.TopBottom;
                _series = Series.Add("series0");
                _series.ChartType = SeriesChartType.Line;
                _series.ShadowOffset = 1;
            }
            public string Title
            {
                get { return _title.Text; }
                set { _title.Text = value; }
            }
            public double Value
            {
                get { return _value; }
                set
                {
                    _value = value;
                    DateTime current = DateTime.Now;
                    _series.Points.AddXY(current.ToOADate(), _value);
                    double removeBefore = current.AddSeconds(-25).ToOADate();
                    while (_series.Points[0].XValue < removeBefore)
                        _series.Points.RemoveAt(0);
                    _area.AxisX.Minimum = _series.Points[0].XValue;
                    _area.AxisX.Maximum
                        = DateTime.FromOADate(_series.Points[0].XValue).AddSeconds(30).ToOADate();
                }
            }
        }
    }
    Note: The TrendChart class is derived from the Framework 4.0 Chart class.
  3. In the constructor, a ChartArea and a Series are added to the chart control,
  4. The control is then configured by setting some ChartArea and Series properties.
  5. Two properties are defined:
    Title Sets a chart title
    Value Binds to a data source
  6. When the data value changes, the set action of the Value property adds a new data point to the chart.
  7. When the number of data points excesses a preset limit, the oldest points are removed.
  8. Open a Command Prompt window.
  9. Change the directory to the path to your new DotNet component folder.

    Example

    C:\Program Files (x86)\Proficy\Proficy CIMPLICITY\exe\DotNet Components\My Samples

  10. Enter the following command.
    C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\csc /t:library /out:ChartControls.dll /r:System.dll;System.Windows.Forms.dll;System.Windows.Forms.DataVisualization.dll TrendChart.cs

Results

A ChartControls.dll is now included in your DotNet components folder.

Note: This TrendChart control can also be built with Visual Studio 11.0. A project for this is included in the folder

..\<CIMPLICITY Install>\exe\DotNet Components\Sample Components\VS2010SampleProjects.

Important: Make sure that the .dll files you use to add  new components are unblocked.
  1. Right-click the file in Windows Explorer.

The Properties dialog box opens.

  1. Select the General tab.
  2. Click Unblock.