Making the AquaGage and AdvancedHMI Control
Now that we have the standard windows control of AquaGage in the project and referenced, it is now time to make an AdvancedHMI control out of it. The trick to making this easy, is to use an existing control as a template. We are going to use the Meter2 as our reference because it is very close in functionality as the AquaGage.
1) Expand down the Controls directory in the AdvancedHMI project
2) Find the Meter2.vb and Right Click->Copy
3) Right Click the Controls folder and select Paste
4) You should now have a new file "Copy of Meter2.vb"
5) Right Click the new file and select Rename
6) Change the name to AquaGage.vb
7) Right Click AquaGage.vb and select View Code
8 ) In the code change "Public Class Meter2" to "Public Class AquaGageHMI"
9) Change "MfgControl.AdvancedHMI.Controls.Meter2" to "Inherits AquaGage.AquaGage"
10) Build the project
After the build, you should have 3 errors. These errors are items from Meter2 that is not part of AquaGage. To resolve this discrepancy, we will comment out (or delete) all of the code associated with the Text property shown below. After commenting out all of that code, you should be able to build with no more errors.
'******************************************************************************************
'* Use the base control's text property and make it visible as a property on the designer
'******************************************************************************************
<System.ComponentModel.Browsable(True)> _
<System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Visible)> _
Public Overrides Property Text() As String
Get
Return MyBase.Text
End Get
Set(ByVal value As String)
If m_Format <> "" And (Not DesignMode) Then
Try
MyBase.Text = Format(CSng(value) * ValueScaleFactor, m_Format)
Catch ex As Exception
MyBase.Text = "Check NumericFormat and variable type"
End Try
Else
'* Highlight in red if an exclamation mark is in text
If InStr(value, "!") > 0 Then
If MyBase.BackColor <> _Highlightcolor Then SavedBackColor = MyBase.BackColor
MyBase.BackColor = _Highlightcolor
Else
If SavedBackColor <> Nothing Then MyBase.BackColor = SavedBackColor
End If
If ValueScaleFactor = 1 Then
MyBase.Text = value
Else
MyBase.Text = value * ValueScaleFactor
End If
End If
End Set
End Property
The AquaGageHMI is now a usable control within AdvancedHMI. You should see it in your Toolbox in the AdvancedHMI Controls group. Add on to the form and use it like any other control.