[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

EKG Lines

Posted on 2006-03-21
10
Medium Priority
?
519 Views
Last Modified: 2008-02-26
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
0
Comment
Question by:schenkp
  • 4
  • 4
  • 2
10 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16249990
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
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16251215
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...
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16251264
Hi, Mikey :)

Bob
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16251292
G'Afternoon Bob!

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

=)
0
 

Author Comment

by:schenkp
ID: 16252633
Idle_Mind
Do you have an example of a vb project or some vb code?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16253971
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
0
 

Author Comment

by:schenkp
ID: 16259818
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
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 16259996
Done.  For the record, I only email a project if the source code is also posted in the thread.  =)
0
 

Author Comment

by:schenkp
ID: 16260757
I checked agian still has not come through?
0
 

Author Comment

by:schenkp
ID: 16260774
GOT IT :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question