Results 1 to 6 of 6

Thread: Create a meter/gauge on a form?

  1. #1

    Thread Starter
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    Hi,
    I want to represent a percent value from 0 to 100 as an analog meter or gauge on a form.
    I'm thinking I have to use the Line function to create the needle and Circle to create the arc.

    Any ideas or suggestions will be greatly appreciated.

    Thanks,
    Al.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Why not to use ProgressBar control that comes with Microsoft Windows Common Controls? Of course, that control cannot create an analog representation as circle, but you can easily calculate the percentage.

  3. #3
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    put a picturebox on a form set border to none
    place a circle in the picture box with bckstyle opaque and choose a back colour

    size the circle to fit the picture box
    use my drawNeedle() procedure passing the reqired percentage as a parameter

    Code:
    Option Explicit
    'Mark Sreeves
    
    Const PI = 3.14157
    Private Function calcX(radius As Single, angle As Single) As Single
        calcX = radius * Cos(angle)
    End Function
    Private Function calcY(radius As Single, angle As Single) As Single
        calcY = radius * Sin(angle)
    End Function
    
    
    
    Private Function degToRad(degrees As Integer) As Single
    
    degToRad = degrees * PI / 180
    
    End Function
    
    Private Sub drawNeedle(percentage As Single)
        Picture1.Cls
        Dim x As Single
        Dim y As Single
        Dim i As Integer
        Dim r As Single 'radius of arc in this instance it's the length of the needle
        Dim centreX As Single
        Dim centreY As Single
        Dim offset As Integer 'this sets where the line starts from
    
        
        r = Picture1.Height / 2
        
        centreX = Picture1.Width / 2
        centreY = Picture1.Height / 2
        
        offset = 180
        
        i = 360 / 100 * percentage 'convert percentage to degrees
            
        x = calcX(r, degToRad(i + offset)) + centreX
        y = calcY(r, degToRad(i + offset)) + centreY
        ' PSet (x, y)
            
        Picture1.Line (centreX, centreY)-(x, y), RGB(255, 0, 0)
        
    End Sub
    Mark
    -------------------

  4. #4

    Thread Starter
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Post

    Hey Mark, Thanks. I would have spent a month-of-Sundays trying to figure this out.

    Serge,
    I'm always looking for a different way to supply upper management with the metrics they want. I already supply bar charts and line graphs.
    Boring.
    I thought I'd try to create something different for this new project, sort of an instrument panel type of measurement display.

    Al.

  5. #5
    New Member
    Join Date
    Jan 2000
    Posts
    8

    Post

    Hi, Al!

    Try ComponentWorks (National Instrument) controls library!
    This is a very good controls.

    HTH

  6. #6
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    You're welcome Al!

    You will probably notice a similarity to the code I knocked-up for Venkat a few days ago!

    http://www.vb-world.net/forums/showthread.php?threadid=10458

    Mark
    -------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width