|
-
Mar 7th, 2000, 09:19 AM
#1
Thread Starter
Hyperactive Member
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.
-
Mar 7th, 2000, 10:19 PM
#2
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.
-
Mar 7th, 2000, 10:32 PM
#3
Frenzied Member
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
-
Mar 8th, 2000, 04:37 AM
#4
Thread Starter
Hyperactive Member
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.
-
Mar 8th, 2000, 05:04 AM
#5
New Member
Hi, Al!
Try ComponentWorks (National Instrument) controls library!
This is a very good controls.
HTH
-
Mar 8th, 2000, 03:19 PM
#6
Frenzied Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|