how to draw analog meter(gauge meter) in vb.net

hi,

i need to draw a full circled gauge meter in a window form.

it should have the needle in the zero position and change accordingly to the value we provide to it

plz help me its urgent




Answer this question

how to draw analog meter(gauge meter) in vb.net

  • Taylor Brown

    You can rawly draw on the winform. Get the Graphics, use the pencil or something else.

    Or for some encapsulation, you may want to make it a control that can be used later, then you have to implement a customed control.

    Which part are you confused with, the GDI+ thing



  • Matevz Gacnik

    Moved to VB forum for better responce.

  • adi151478

    i want to design it as a windowcontrol library

    i have done it in vb6 with three different gif images and its working fine.

    i dont know the similar syntax in vb.net.

    in vb6 picture1.line is used to draw the line in picture box . In vb.net i dont know how to draw it.

    pl help me on this

    the source code for vb6 follows:

    Dim sl As Integer
    Dim r1 As Double
    Dim r2 As Double
    Const vbPI = 3.141592654
    Const Deg2Rad = vbPI / 180 'Degrees to Radians
    Dim cx As Integer, cy As Integer, r As Single
    Dim s As Double

    Private Sub Form_Load()
    'Form1.Left = (Screen.Width / 2) - (Form1.Width / 2)
    'Form1.Top = (Screen.Height / 2) - (Form1.Height / 2)
    'zero-out all the meters
    For X = 0 To 3
    VScroll1(X).Value = 0
    Next X
    End Sub

    Private Sub analogmeter(Index As Integer, Mtype As Integer, Emin As Double, Emax As Double, _
    Mmin As Double, Mmax As Double, Handw As Integer, Color As String, Handl As Double, _
    Value As Double)

    If Mtype = 1 Then
    Mdeg = 0 ' degrees (0-360)
    cx = Picture1(Index).Width / 2
    cy = Picture1(Index).Height / 2
    End If
    If Mtype = 2 Then
    Mdeg = 270 ' degrees (0-360)
    cx = Picture1(Index).Width / 2
    cy = (Picture1(Index).Height - 2)
    End If

    ' Scale the dial hand length
    r = IIf(cx > cy, cy, cx) - 5
    sl = r * Handl 'length of meter hand

    ' Scale the Engineering Units
    r1 = Emax - Emin
    r2 = Mmax - Mmin
    s = ((r2 / r1) * Value) + Mmin

    ' Draw the dial hand
    sin_ = Sin((Mdeg - s * 6) * Deg2Rad) * (r - sl) + cx
    cos_ = Cos((Mdeg - s * 6) * Deg2Rad) * (r - sl) + cy
    oldcolor = vbBlack
    Picture1(Index).ForeColor = Color
    Picture1(Index).DrawWidth = Handw
    Picture1(Index).Cls
    Picture1(Index).Line (cx, cy)-(sin_, cos_)
    Picture1(Index).ForeColor = oldcolor

    End Sub

    Private Sub VScroll1_Change(Index As Integer)
    ' Update Meter values
    Label5(Index) = VScroll1(Index).Value
    If Index = 0 Then ' Air Pressure Meter
    analogmeter Index, 1, 0, 120, 7, 53, 2, vbRed, 0.1, VScroll1(Index).Value
    End If
    If Index = 1 Then ' Motor RPM Meter
    analogmeter Index, 2, 0, 100, 0, 30, 3, vbBlue, 0.1, VScroll1(Index).Value
    End If
    If Index = 2 Then ' Valve Position Meter
    analogmeter Index, 2, 0, 100, 0, 30, 2, vbBlack, 0.1, VScroll1(Index).Value
    End If
    If Index = 3 Then ' Temperature Meter
    analogmeter Index, 2, 0, 300, 0, 30, 4, vbRed, 0.1, VScroll1(Index).Value
    End If
    End Sub



  • how to draw analog meter(gauge meter) in vb.net