In this section, I’ll show complete demo of how to create Custom User Control in C# windows applications.
I’ll show descriptions of custom user control and basics of the custom user control. After learning this document you will be able to make the custom user control according to your own requirement.
Custom Usercontrol programming
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ATPropertyEditor;
namespace ATSCADA.iWinTools
{
// iStatus is an UserControl that is used to show the connection status of tags
public partial class iStatus : UserControl
{
protected string _TagName; //tag name
protected string _TaskName; //task name
protected iDriver _Driver; //driver name
protected Timer _SysTimer; // processing timer
// Add Tag
[Description(“Select Tag for SCADA control”)]
[TypeConverter(typeof(TaskConverter)), CategoryAttribute(“ATSCADA Settings”)]
public string TagName
{
get
{
return _TaskName + “.” + _TagName;
}
set
{
_TaskName = value.Split(‘.’)[0];
_TagName = value.Split(‘.’)[1];
}
}
// Add driver
[Description(“Select Driver for SCADA control”)]
[Browsable(true), Category(“ATSCADA Settings”)]
public iDriver Driver
{
get
{
return _Driver;
}
set
{
_Driver = value;
}
}
private void iUpdateValue(object o, TagStatusEventArgs e)
{
try
{
//Update Label Value
string nv;
nv = e.NewStatus;
if (nv == “Good”) // if the conncetion status is good,the backcolor of iStatus will be green
this.BackColor = Color.LimeGreen;
else // else if the connection status is bad, the backcolor of iStatus will be red
this.BackColor = Color.Red;
}
catch { }
}
private void _SysTimer_Tick(object o, EventArgs e)
{
//In runtime
try
{
//Attach Driver for Item
//Get the Tag with _TagName
if ((_TagName != null) && (_Driver != null) && (_Driver.Task(_TaskName) != null))
{
//Get Update Event from tag
if (_Driver.Task(_TaskName).Tag(_TagName) != null)
{
_Driver.Task(_TaskName).Tag(_TagName).TagStatusChanged += new TagStatusHandler(iUpdateValue);
//Init Value
if (_Driver.Task(_TaskName).Tag(_TagName).Status == “Good”) // check the connection status of tag, if status is good,the backcolor of iStatus will be green
this.BackColor = Color.LimeGreen;
else // else if status is bad, the backcolor of iStatus will be red
this.BackColor = Color.Red;
}
_SysTimer.Enabled = false;
_SysTimer.Dispose();
}
}
catch { }
}
// initialize iStatus
public iStatus()
{
InitializeComponent();
try
{
//not support design time
if (System.Diagnostics.Process.GetCurrentProcess().ProcessName == “devenv”
|| System.Diagnostics.Process.GetCurrentProcess().ProcessName == “VCSExpress”
|| System.Diagnostics.Process.GetCurrentProcess().ProcessName == “vbexpress”
|| System.Diagnostics.Process.GetCurrentProcess().ProcessName == “WDExpress”)
{
return;
}
}
catch
{
return;
}
// initialize Timer for runtime
_SysTimer = new Timer();
_SysTimer.Interval = 1000;
_SysTimer.Tick += new EventHandler(_SysTimer_Tick);
_SysTimer.Enabled = true;
}
}
}
>> Reference: English – Traning Cources
Contact:
If you are interested in ATSCADA Custom Usercontrol programming. Please contact ATSCADA Lab hotline for quick support.
Thank you.
ATSCADA - Providing ATSCADA software - The monitoring and data acquisition control system is the appropriate choice for integrated system projects, IoT, smart city projects, agriculture 4.0... Is trusted by many customers.
Related posts
ATSCADA Installation Guide
Video ATSCADA Installation Guide The following video shows the steps of ATSCADA installation. If having any [...]
Oct
ATSCADA – Software Architecture
Tìm hiểu về ATSCADA – Kiến trúc phần mềm ATSCADA được thiết kế trên KIẾN [...]
Oct
ATSCADA Graphic Tools
ATSCADA Graphics Tool Guide ATSCADA Graphic Tools: iGraphic, iImageButton, iGauge, iHBar, iVBar, iMotion Picture, iRealtime [...]
Oct
ATSCADA Advanced Programming: Email, SMS programming
In the SCADA applications, sometimes you need to send notifications email or SMS to your [...]
Sep
ATSCADA Advanced Programming Tag Events
In advanced programming, we usually use tag events to do some duties, we have two [...]
Sep
ATSCADA Advanced Programming Tag Read/Write
In advanced programming, sometimes we need to read the tag value or write the tag [...]
Sep