EKG Lines

HI,
Im interested in drawing some lines in realtime on a form over and over agian, from one point to another.  It might look the way an EKG looks, not sure where to begin though.

Thanks

Peter
schenkpAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
1) Begin with the Paint event for the form.  

2) Look at GDI+.  

3) There are options to draw lines, curves, beziers, rectangles, etc.

Bob
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
For an EKG type graph where things scroll to the left and then disappear you could use the BitBlt API.  Basically you start by shifting your "graph" one pixel to the left via BitBlt().  Then you simply draw the new points at the very rightmost X position in your graph.  Repeat...

This works because the stuff that scrolls to the left doesn't change amplitude...it just changes X position.  The only new things that need to be drawn are the very rightmost points.

I haven't done this in C# but it have used it with great success in VB6...
Bob LearnedCommented:
Hi, Mikey :)

Bob
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
G'Afternoon Bob!

I'm off to lunch with the kids (it's spring break)...

=)
schenkpAuthor Commented:
Idle_Mind
Do you have an example of a vb project or some vb code?
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Here is a VB6 example.  Create a New Project and add a PictureBox and a Timer control.  Set the forms BorderStyle property to 1- Fixed Single:

Option Explicit

Private Const SRCCOPY = &HCC0020

Private Declare Function BitBlt Lib "gdi32" ( _
    ByVal hDestDC As Long, _
    ByVal x As Long, ByVal y As Long, _
    ByVal nWidthMax As Long, ByVal nHeightMax As Long, _
    ByVal hSrcDC As Long, _
    ByVal xSrc As Long, ByVal ySrc As Long, _
    ByVal dwRop As Long) As Long

Private cnt As Integer
Private lastValue As Single
Private baseline As Long

Private Sub Form_Load()
    Randomize Timer
    Me.Width = 9900
    Me.Height = 3855
    Me.Caption = "Real Time Graph with Grid Demo"
    Picture1.ScaleMode = vbPixels
    Picture1.AutoRedraw = True
    Picture1.Appearance = 0 ' flat
    Picture1.BorderStyle = 0 ' none
    Picture1.BackColor = vbBlack
    Picture1.Left = 0
    Picture1.Top = 0
    Picture1.Width = Me.ScaleWidth
    Picture1.Height = Me.ScaleHeight
    baseline = RGB(255 * 0.75, 255 * 0.75, 255 * 0.75)
    Timer1.Interval = 25
    Timer1.Enabled = True
    lastValue = Picture1.ScaleHeight / 2 ' start in the middle
    cnt = -1
End Sub

Private Sub Timer1_Timer()
    ' move everything to the left one pixel
    Call BitBlt(Picture1.hDC, -1, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hDC, 0, 0, SRCCOPY)
   
    ' clear the last column
    Picture1.Line (Picture1.ScaleWidth - 1, 0)-(Picture1.ScaleWidth - 1, Picture1.ScaleHeight), Picture1.BackColor
   
    ' draw the grid first
    cnt = cnt + 1
    If cnt Mod 25 = 0 Then
        cnt = 0
        Picture1.Line (Picture1.ScaleWidth - 1, 0)-(Picture1.ScaleWidth - 1, Picture1.ScaleHeight), vbWhite
    Else
        Dim i As Integer
        For i = 25 To Picture1.ScaleHeight Step 25
            Picture1.PSet (Picture1.ScaleWidth - 1, i), vbWhite
        Next
    End If
   
    ' make the plot go up and down randomly
    Dim delta As Single
    Dim chance As Single
    Dim modifier As Single
    Dim newValue As Single
    Dim newValue2 As Single
   
    Select Case lastValue
        Case Is < Picture1.ScaleHeight * 1 / 3
            modifier = (Picture1.ScaleHeight * 1 / 3 - lastValue) / Picture1.ScaleHeight * 1 / 3 * 0.5
            chance = 0.5 + modifier
            delta = (1 - chance) * (CSng(Picture1.ScaleHeight) / CSng(25) + 1) * Rnd
            delta = IIf(Rnd() <= chance, delta, -1 * delta)
           
        Case Is > Picture1.ScaleHeight * 2 / 3
            modifier = (lastValue - Picture1.ScaleHeight * 2 / 3) / Picture1.ScaleHeight * 1 / 3 * 0.5
            chance = 0.5 + modifier
            delta = (1 - chance) * (CSng(Picture1.ScaleHeight) / CSng(25) + 1) * Rnd
            delta = IIf(Rnd() <= chance, -1 * delta, delta)
           
        Case Else
            chance = 0.5
            delta = (1 - chance) * (CSng(Picture1.ScaleHeight) / CSng(25) + 1) * Rnd
            delta = IIf(Rnd() < chance, -1 * delta, delta)
           
    End Select
    newValue = lastValue + delta
    If newValue < 0 Then
        newValue = 0
    ElseIf newValue > Picture1.ScaleHeight - 1 Then
        newValue = Picture1.ScaleHeight - 1
    End If
           
    ' change the color based on its amplitude
    Dim p As Single
    Dim clr As Long
    p = lastValue / Picture1.ScaleHeight
    clr = RGB(255, (1 - p) * 192, (1 - p) * 192)
   
    ' draw a line from the last point to the new point
    Picture1.Line (Picture1.ScaleWidth - 2, lastValue)-(Picture1.ScaleWidth - 1, newValue), clr
   
    ' store the new point
    lastValue = newValue
End Sub
schenkpAuthor Commented:
Idle_Mind,
Could you please email mail me this project to <email deleted>, I am having issues getting this to work.

Thanks

Peter

TheLearnedOne
Page Editor
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Done.  For the record, I only email a project if the source code is also posted in the thread.  =)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
schenkpAuthor Commented:
I checked agian still has not come through?
schenkpAuthor Commented:
GOT IT :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.