Author Topic: Bar Level as percentage  (Read 1657 times)

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Bar Level as percentage
« on: February 12, 2018, 07:44:12 PM »
Hello AHMI world.  I want to use the Bar Level as a percentage rather than a raw value.  What I noticed is that if the value goes beyond the max value, the text will move off the end of the control and not be visible.  There are times my value will go beyond 100% during overloads and I want the value to still be seen.  I was wondering how I can change the text to be fixed in the center of the bar level and not follow the fill line?  Similar to the attached pic,  Thanks.   

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Bar Level as percentage
« Reply #1 on: February 13, 2018, 02:38:31 PM »
I did a little "googling" and came across this code which does paint the value in the center of the control, however it seems to flicker on/off so fast that it can hardly be seen.  Is there a trick to keep this visible?

 thanks


    Private Sub BarLevel1_ValueChanged(sender As Object, e As EventArgs) Handles BarLevel1.ValueChanged
        percent = CInt(Me.BarLevel1.Value)
        Using gr
            gr = BarLevel1.CreateGraphics

            gr.DrawString(percent & "%", Me.Font, Brushes.Black, _
                          Me.BarLevel1.Width / 2 - (gr.MeasureString(percent & "%", SystemFonts.DefaultFont).Width / 2.0F), _
                          Me.BarLevel1.Height / 2 - (gr.MeasureString(percent & "%", SystemFonts.DefaultFont).Height / 2.0F))

           End Using

    End Sub

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Bar Level as percentage
« Reply #2 on: February 13, 2018, 03:17:16 PM »
See if this gets you what you want:

- Download the attached file
- With AdvancedHMI open, in Solution Explorer expand down the AdvancedHMIControls project
- Right click the PurchasesControls folder and select Add Existing Item
- Browse to the BarLevelEx.vb from this post
- In the Controls folder, right click BarLevel.vb and select view code
- Change the Inherits at about line 27 to this:
    Inherits BarLevelEx
- Rebuild the solution

- Add a Barlevel to the form
- Set the FillDiection to Right
- Set CenterValue to True

MrPike

  • Sr. Member
  • ****
  • Posts: 297
    • View Profile
Re: Bar Level as percentage
« Reply #3 on: February 13, 2018, 03:34:02 PM »
Perfect Archie!  Works like a charm :)