Author Topic: A Colorful Progress Bar / Bar Level  (Read 5550 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
A Colorful Progress Bar / Bar Level
« on: December 09, 2014, 08:32:20 PM »
There are a number of free example custom controls around the internet that are easy to add to an AdvancedHMI solution. One example can be found here:

https://code.msdn.microsoft.com/Custom-Colored-ProgressBar-a68b61de/view/Reviews

To add this to your AdvancedHMI project follow these steps:

1) Right click the PurchasedControls folder in the AdvancedHMIControl project in Solution Explorer
2) Select Add Class
3) Give it the name ProgressBarEx
4) Delete the two lines of code
5) Copy all of the code from the web link above and paste into the new class

At this point you can Build the project and you should get a ProgressBarEx in your Toolbox. The ProgressBarEx is now a simple windows form control. We now need to make this into an AdvancedHMI control.

1) In the Controls folder of the AdvancedHMIControls project in Solution Explorer, right click BarLevel and select Copy
2) Right click the Controls folder and select paste
3) Right click the new file (Copy of BarLevel.vb) and select rename
4) Change the name to ProgressBarExHMI.vb
5) Right click the new file and select View Code
6) About 26 lines down, if neceaary, change the name from BarLevel to ProgressBarExHMI
6a) About 27 lines down you will see the code  Inherits MfgControl.AdvancedHMI.Controls.BarLevel
7) Change this to Inherits ProgressBarEx
8 ) You will get 3 errors because the ProgressBarEx does not have a ValueScaleFactor property. This is resolved by deleting the overridden property of Text. Delete all of this code:
Code: [Select]
    '******************************************************************************************
    '* 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) * m_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 m_ValueScaleFactor = 1 Then
                    MyBase.Text = value
                Else
                    MyBase.Text = value * m_ValueScaleFactor
                End If
            End If
        End Set
    End Property
9) Build the Solution

You should now have a ProgressBarExHMI in your Toolbox
« Last Edit: December 10, 2014, 02:40:00 AM by Archie »

DougLyons

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
A Colorful Progress Bar / Bar Level
« Reply #1 on: December 09, 2014, 11:37:27 PM »
Archie,

Thanks for this great tutorial. I have gone through the steps and I had to do two more things.
Here is what I had to do between step 5 and 6:

5a) About 26 lines down you will see the code "Public Class BarLevel"
5b) Change this to "Public Class ProgressBarExHMI"

Without this I received this error:

class 'BarLevel' and class 'BarLevel', declared in 'C:\Users\lyonsdo\Documents\Visual Studio 2013\Projects\AdvancedHMIBetaV389\AdvancedHMIControls\Controls\BarLevel.vb', conflict in namespace 'AdvancedHMIControls'.   C:\Users\lyonsdo\Documents\Visual Studio 2013\Projects\AdvancedHMIBetaV389\AdvancedHMIControls\Controls\ProgressBarExHMI.vb

Thanks again.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: A Colorful Progress Bar / Bar Level
« Reply #2 on: December 10, 2014, 02:45:36 AM »
Thanks for catching that, I corrected the steps. When I did my quick test, I didn't 100% type out the steps I used, so I overlooked that sometimes, but not always, Visual Studio will rename a class for you.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: A Colorful Progress Bar / Bar Level
« Reply #3 on: December 21, 2014, 04:05:44 PM »
If someone is looking to add a simple 7-segment LED display user control, can find all the steps and code in this tutorial on Dream.In.Code website: www.dreamincode.net/forums/topic/56377-making-a-user-control/
The code on the very bottom of the tutorial also shows the usage example in the form of Clock.

As suggested here, in the first post by Archie, the first 5 steps would make it a simple windows form control that can be referenced in the vb code (similar to that Clock example).

It should be possible to make it an AdvancedHMI control as well.