Locked line graph

  • Tuesday, September 02, 2008 2:25 PM
     
      Has Code
    Good day!!

    To all who have answer my recent Question thank you very much!!!

    Now is there somebody who could help me use line graph to display the rate of increase of water level???
    I'm using Microsoft Visual Basic 2005 express Edition.. I'm just a beginner and I really cant figure out how the line graph work,, hope somebody could assist me to make this line graph display the rate of increase of water level... thank you!!!
     

All Replies

  • Tuesday, September 02, 2008 3:13 PM
     
     

    Hi Al-al

    At first sight, you may think that is a very easy question - and probably is what you may possibly be thinking.

    Basically, you want two axes - an horizontal x and a vertical y - marked and scaled suitably. No problem.

    Then for every value of x, you need to draw a line from the last point plotted to the corresponding x,y point - and somehow mark the new x,y point. Ok Still relatively easy.

    With real-world data though you may (indeed probably will) find that the line is a bit staggered.

    We can say, that due to experimental/observational errors (which ARE unavoidable), the points are actually staggered about a line representing the true function of the relationship between y and x.

    So this is where it starts to be not so simple a task. What you actually require is a best fit line - a line that represents a kind of mean of the points.

    Now there are standard algorithms for best fit lines. BUT be warned, some of them search for and find a curve that passes through the majority of points - this is not as good news as it might sound because so very often (most of the time) these best fit lines are polynominal lines - e.g. x to some power m.

    So, purely because of experimental error, you could end up with a line of a quadratic function, or worse, a cubic function when really it should be a straight line, say, but the program was 'misled' by the data.

    Now perhaps you start to see the problem and why no-ones helped you yet. Now I am assuming that the function is a linear one and be described by the equation of a straight line:

    y=mx+c

    If so, I recommend you draw your axes, a straight line of the form y=mx+c in one colour (this is the 'ideal' line) and plot your points and draw your 'staggered' line in a different colour - then you can begin to see how much your data deviates from the ideal.
    Whoever answers you question will need the  y and x axis units, the maximum and minimum amounts (though min could be taken as being the origin (0,0), and the actual data.

    Drawing lines in 2D is no big deal in Vb.net and the help files should be all you need - even if you are relatively new to vb.net and programming.

    Or at least, please, give a table of x and y results so somebody can help you code it.
    Allan

  • Tuesday, September 02, 2008 3:15 PM
     
     
    Hi Al-al,

    Why not continue your original question at.>>

    http://forums.msdn.microsoft.com/en-US/vblanguage/thread/c6654d7c-08b2-413e-be3a-bb98fa9944d8

    instead of starting a new question?




    Regards,

    John


    .--- --- .... -.
  • Tuesday, September 02, 2008 3:20 PM
     
     
    bigamee said:

    Hi Al-al

    Or at least, please, give a table of x and y results so somebody can help you code it.

    Allan


    Hi Al-al,

    I will 2nd the request for the data you need to be plotted as requested by forum user ( bigamee a.k.a Allan ),  so please post the data you need plotted.




    Regards,

    John


    .--- --- .... -.
  • Thursday, September 04, 2008 8:40 AM
     
      Has Code
    HI to everyone!!
     thank you very much!!

    heres my data of my axes

    Y axis - repsent the water level..level (1 - 4)
    X axis - time (60 sec),


    i have only four sensors that's why I only have up to level four.. i only uses second as my unit of time interval this would probobly look like the task manager of windows...thank you very much for your help!!

  • Thursday, September 04, 2008 11:20 AM
     
     

    Hi Al-al

    You've supplied enough info for the axes to be constructed.

    And the actual data?

    Something like:

    Y (water level)

    .5    1    1.5    2

    x (secs)

    1    15   30   45

    Then we can plot the graph.

    Allan

     

  • Thursday, September 04, 2008 12:38 PM
    Moderator
     
     
    As answered in one of your previous threads asking the same question:

    http://forums.msdn.microsoft.com/en-US/vblanguage/thread/744998a0-5c4a-4a98-ba86-9145182abdf4/

    "It is the best option to use the Zedgraph support forum for asking this product questions."


    Stephen J Whiteley
  • Thursday, September 04, 2008 1:54 PM
     
      Has Code
    Hi Al-al,

    Assuming the following data;

        'Four fictional levels.>>
        Dim levels() As Integer = {1, 2, 3, 4}

        'Four fictional time intervals.>>
        Dim intervals() As Integer = {4, 22, 26, 60}

    Meaning that;

    • At 4 we are up to Level 1
    • At 22 we are up to Level 2
    • At 26 we are up to Level 3
    • At 60 we are up to Level 4

    If 4 line sections are sufficient then alter the data in the code below, otherwise let me know please.

    The following code plots the line in 4 different color sections on a Maximized FORM.>>




    Public Class Form1

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.WindowState = FormWindowState.Maximized
        Me.BackColor = Color.Black

      End Sub

      Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        Dim myPen As New Pen(Color.White)
        'Draw the vertical axis.>>
        e.Graphics.DrawLine(myPen, 100, 0, 100, Me.Height - 75)
        'Draw the horizontal axis.>>
        e.Graphics.DrawLine(myPen, 100, Me.Height - 75, Me.Width, Me.Height - 75)

        'I will deliberately not use index zero.>>
        Dim verticalAxisMarks(4) As Integer
        Dim vSpacing As Integer = (Me.Height - 75) \ 5
        Dim startY As Integer = Me.Height - 75
        For num As Integer = 1 To 4
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startY = startY - vSpacing
          verticalAxisMarks(num) = startY
          'Draw the little red marks on the vertical axis.>>
          e.Graphics.DrawLine(myPen, 95, startY, 105, startY)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 15 Arial Font.>>
          Dim myFont As New Font("Arial", 15)
          'Draws the strings Level1 to Level4 within the FOR NEXT loop.>>
          e.Graphics.DrawString("Level" & num.ToString, myFont, myBrush, 10, startY)

          myPen = New Pen(Color.LightGray)
          'Draw horizontal graph lines.>>
          e.Graphics.DrawLine(myPen, 100, startY, Me.Width, startY)
        Next

        'I will deliberately not use index zero.>>
        Dim horizontalAxisMarks(60) As Integer
        Dim hSpacing As Integer = (Me.Width - 100) \ 70
        Dim startX As Integer = 100
        For num As Integer = 1 To 60
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startX = startX + hSpacing
          horizontalAxisMarks(num) = startX
          'Draw the little red marks on the horizontal axis.>>
          e.Graphics.DrawLine(myPen, startX, Me.Height - 70, startX, Me.Height - 80)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 10 Arial Font.>>
          Dim myFont As New Font("Arial", 10)
          'Draws the strings  5 , 10 15, 20, 25, 30, 35, 40, 45, 50, 55 and 60  within the FOR NEXT loop.>>
          If num Mod 5 = 0 Then
            e.Graphics.DrawString(num.ToString, myFont, myBrush, startX, Me.Height - 70)
          End If

          myPen = New Pen(Color.LightGray)
          'Draw vertical graph lines.>>
          e.Graphics.DrawLine(myPen, startX, 0, startX, Me.Height - 75)
        Next

        'Four fictional levels.>>
        Dim levels() As Integer = {1, 2, 3, 4}
        'Four fictional time intervals.>>
        Dim intervals() As Integer = {4, 22, 26, 60}

        Dim myPoints(4) As Point
        For num As Integer = 0 To 3
          myPoints(num).X = horizontalAxisMarks(intervals(num))
          myPoints(num).Y = verticalAxisMarks(levels(num))
        Next
        myPoints(4) = New Point(100, Me.Height - 75)

        'Draw four lines for the graph in different colors.>>
        e.Graphics.DrawLine(New Pen(Color.Red, 4), myPoints(0), myPoints(1))
        e.Graphics.DrawLine(New Pen(Color.Green, 4), myPoints(1), myPoints(2))
        e.Graphics.DrawLine(New Pen(Color.Blue, 4), myPoints(2), myPoints(3))
        e.Graphics.DrawLine(New Pen(Color.Yellow, 4), myPoints(0), myPoints(4))

      End Sub

    End Class




    Regards,

    John


    .--- --- .... -.
    • Edited by John Anthony Oliver Thursday, September 04, 2008 10:56 PM Added As Integer for VB.Net 2005
    •  
  • Thursday, September 04, 2008 2:11 PM
     
      Has Code
    To start you off:

    Here's the axis with ticks marks - going from 0 to 5 on the vertical axis
    and with seconds tick marks going from 0 to 10 on the horizontal axis.
    Put a picturebox on the form. Set its dock property to none and its anchor property to Top,Bottom, Left, Right.
    The graph is in the picturebox paint event so should be permanently shown - and redrawn appropriately (within reason) on a form resize.
    Allan

    Public Class Form1  
        Private Sub PictureBox1_Paint(ByVal sender As ObjectByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint  
            Dim LeftMargin As Integer = 40  
            Dim BaseMargin As Integer = 40  
            Dim TopMargin As Integer = 40  
            Dim RightMargin As Integer = 40  
            Dim VertLineLength As Integer = PictureBox1.Height - (BaseMargin + TopMargin)  
            Dim HorzLineLength As Integer = PictureBox1.Width - (LeftMargin + RightMargin)  
            Dim VertGap As Integer = CInt(VertLineLength / 5)  
            Dim HorzGap As Integer = CInt(HorzLineLength / 10)  
            Dim StartPoint As New Point(LeftMargin, PictureBox1.Height - BaseMargin)  
            Dim EndPoint As New Point(LeftMargin, TopMargin)  
            Dim TickSP As New Point(LeftMargin - 5, StartPoint.Y - VertGap)  
            Dim TickEP As New Point(LeftMargin, StartPoint.Y - VertGap)  
            Dim ValueFont As New Font("Arial", 8, FontStyle.Regular)  
     
            '   Draw a line for the Vertical Axis.  
     
            '  Basic Pen to draw outline lines  
            Dim LinePen As New Pen(Color.Black, 2)  
            '  Draw the vertical line  
            e.Graphics.DrawLine(LinePen, StartPoint, EndPoint)  
     
            For i As Integer = 1 To 5  
                '  Tick mark  
                e.Graphics.DrawLine(New Pen(Color.Black), TickSP, TickEP)  
                '  Tick Values as text   
                e.Graphics.DrawString(CStr(i), ValueFont, Brushes.Black, 2, TickSP.Y - 5)  
                '  Reset y positions, moving 20% up vertical line  
                TickSP.Y -= VertGap  
                TickEP.Y -= VertGap  
            Next 
            'Draw a line for the horizontal axis  
            e.Graphics.DrawLine(LinePen, LeftMargin, PictureBox1.Height - BaseMargin, PictureBox1.Width - RightMargin + 6, PictureBox1.Height - BaseMargin)  
            TickSP = New Point(LeftMargin + HorzGap, StartPoint.Y)  
            TickEP = New Point(LeftMargin + HorzGap, StartPoint.Y + 5)  
     
            For i As Integer = 1 To 10 'Assume 0 to 10 secs  
                '  Tick mark  
                e.Graphics.DrawLine(New Pen(Color.Black), TickSP, TickEP)  
                '  Tick Values as text   
                e.Graphics.DrawString(CStr(i), ValueFont, Brushes.Black, TickSP.X - 5, PictureBox1.Height - 30)  
                '  Reset x positions, moving 10% along horizontal line  
                TickSP.X += HorzGap  
                TickEP.X += HorzGap  
            Next 
        End Sub 
     
        Private Sub Form1_Resize(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Resize  
            PictureBox1.Invalidate()  
        End Sub 
    End Class 
     
    • Marked As Answer by Al-al Friday, September 05, 2008 2:25 PM
    • Unmarked As Answer by Al-al Friday, September 05, 2008 3:46 PM
    •  
  • Thursday, September 04, 2008 2:12 PM
     
     
    You beat me to it John
    Was going to let you handle it anyways because you know V.Net graphics better than me.
    Allan
  • Thursday, September 04, 2008 2:15 PM
     
     
    bigamee said:

    You beat me to it John
    Was going to let you handle it anyways because you know V.Net graphics better than me.
    Allan


    Hi Allan,

    I think the OP Al-al has got 3 threads going regarding graphing!!

    I thought I'd do it with a Maximised FORM as it is easier to see.  ;-)

    As you see, you don't need a PictureBox.  :-)

    I've drawn on the FORM itself.




    Regards,

    John


    .--- --- .... -.
  • Thursday, September 04, 2008 2:16 PM
     
     
    Just ran yours John - and yours, not surprisingly, is a lot better than mine.
    Allan
  • Thursday, September 04, 2008 2:17 PM
     
     
    bigamee said:

    Just ran yours John - and yours, not surprisingly, is a lot better than mine.
    Allan


    Hi Allan,

    I've not tried yours yet. :-)
    Thanks for the compliment. ;-)


    Regards,

    John


    .--- --- .... -.
  • Thursday, September 04, 2008 2:21 PM
     
     

    And all he's got to do is modify the values in the apropriate dim(s). to match his own data :)

    Brill.

    Allan

     

  • Thursday, September 04, 2008 2:23 PM
     
     
    John Anthony Oliver said:

    bigamee said:

    Just ran yours John - and yours, not surprisingly, is a lot better than mine.
    Allan


    Hi Allan,

    I've not tried yours yet. :-)
    Thanks for the compliment. ;-)


    Regards,

    John


    .--- --- .... -.



    Yw - I do appreciate your expertise with .Net graphics.
    Allan
  • Thursday, September 04, 2008 2:26 PM
     
     
    Mines a modified version of one on Devcity or some such VB helper site.
    Allan
  • Thursday, September 04, 2008 2:43 PM
     
     
    bigamee said:


    Yw - I do appreciate your expertise with .Net graphics.
    Allan


    Hi Allan,

    Thanks again. :-D
    I'm not an "expert" as I've not tried all of the VB.Net graphics methods yet!! ...LOL!!

    I have not tried my code at 800 X 600 screen resolution,
    mine is set at 1024 X 768 which is pretty commonly used I think.

    I would need to tweak my code if the user wanted a Level of say half way to Level 1 at say 12 seconds.
    I used the INTEGER type for the ARRAYS anyway. ;-)

    It only took about 20 minutes for me to write the code off the top of my head with a bit of experimentation regarding the plot Points.


    Regards,

    John


    .--- --- .... -.
    • Edited by John Anthony Oliver Thursday, September 04, 2008 2:49 PM Added a further comment.
    •  
  • Thursday, September 04, 2008 3:01 PM
     
     Proposed Has Code
    Hi Allan,

    It looks even better like this. I have highlighted in yellow the two slight code changes.  :-)


    Regards,

    John




    Option Strict On

    Public Class Form1

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.WindowState = FormWindowState.Maximized
        Me.BackColor = Color.Black

      End Sub

      Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        Dim myPen As New Pen(Color.White)
        'Draw the vertical axis.>>
        e.Graphics.DrawLine(myPen, 100, 0, 100, Me.Height - 75)
        'Draw the horizontal axis.>>
        e.Graphics.DrawLine(myPen, 100, Me.Height - 75, Me.Width, Me.Height - 75)

        'I will deliberately not use index zero.>>
        Dim verticalAxisMarks(4) As Integer
        Dim vSpacing As Integer = (Me.Height - 75) \ 5
        Dim startY As Integer = Me.Height - 75
        For num As Integer = 1 To 4
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startY = startY - vSpacing
          verticalAxisMarks(num) = startY
          'Draw the little red marks on the vertical axis.>>
          e.Graphics.DrawLine(myPen, 95, startY, 105, startY)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 15 Arial Font.>>
          Dim myFont As New Font("Arial", 15)
          'Draws the strings Level1 to Level4 within the FOR NEXT loop.>>
          e.Graphics.DrawString("Level" & num.ToString, myFont, myBrush, 10, startY)

          myPen = New Pen(Color.LightGray)
          'Draw horizontal graph lines.>>
          e.Graphics.DrawLine(myPen, 100, startY, Me.Width, startY)
        Next

        'I will deliberately not use index zero.>>
        Dim horizontalAxisMarks(60) As Integer
        Dim hSpacing As Integer = (Me.Width - 100) \ 64
        Dim startX As Integer = 100
        For num As Integer = 1 To 60
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startX = startX + hSpacing
          horizontalAxisMarks(num) = startX
          'Draw the little red marks on the horizontal axis.>>
          e.Graphics.DrawLine(myPen, startX, Me.Height - 70, startX, Me.Height - 80)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 10 Arial Font.>>
          Dim myFont As New Font("Arial", 10)
          'Draws the even number strings 2 to 60 within the FOR NEXT loop.>>
          If num Mod 2 = 0 Then
            e.Graphics.DrawString(num.ToString, myFont, myBrush, startX, Me.Height - 70)
          End If

          myPen = New Pen(Color.LightGray)
          'Draw vertical graph lines.>>
          e.Graphics.DrawLine(myPen, startX, 0, startX, Me.Height - 75)
        Next

        'Four fictional levels.>>
        Dim levels() As Integer = {1, 2, 3, 4}
        'Four fictional time intervals.>>
        Dim intervals() As Integer = {4, 22, 26, 60}

        Dim myPoints(4) As Point
        For num As Integer = 0 To 3
          myPoints(num).X = horizontalAxisMarks(intervals(num))
          myPoints(num).Y = verticalAxisMarks(levels(num))
        Next
        myPoints(4) = New Point(100, Me.Height - 75)

        'Draw four lines for the graph in different colors.>>
        e.Graphics.DrawLine(New Pen(Color.Red, 4), myPoints(0), myPoints(1))
        e.Graphics.DrawLine(New Pen(Color.Green, 4), myPoints(1), myPoints(2))
        e.Graphics.DrawLine(New Pen(Color.Blue, 4), myPoints(2), myPoints(3))
        e.Graphics.DrawLine(New Pen(Color.Yellow, 4), myPoints(0), myPoints(4))

      End Sub

    End Class


    .--- --- .... -.
    • Proposed As Answer by bigamee Thursday, September 04, 2008 3:31 PM
    • Edited by John Anthony Oliver Thursday, September 04, 2008 10:58 PM Added As Integer for VB.Net 2005
    • Marked As Answer by Xingwei Hu Monday, September 08, 2008 2:52 AM
    • Unmarked As Answer by Al-al Monday, September 08, 2008 1:59 PM
    •  
  • Thursday, September 04, 2008 3:31 PM
     
     
    John Anthony Oliver said:

    Hi Allan,


    It looks even better like this. I have highlighted in yellow the two slight code changes.  :-)


    Regards,

    John




    Option Strict On

    Public Class Form1

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.WindowState = FormWindowState.Maximized
        Me.BackColor = Color.Black

      End Sub

      Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        Dim myPen As New Pen(Color.White)
        'Draw the vertical axis.>>
        e.Graphics.DrawLine(myPen, 100, 0, 100, Me.Height - 75)
        'Draw the horizontal axis.>>
        e.Graphics.DrawLine(myPen, 100, Me.Height - 75, Me.Width, Me.Height - 75)

        'I will deliberately not use index zero.>>
        Dim verticalAxisMarks(4) As Integer
        Dim vSpacing As Integer = (Me.Height - 75) \ 5
        Dim startY As Integer = Me.Height - 75
        For num As Integer = 1 To 4
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startY = startY - vSpacing
          verticalAxisMarks(num) = startY
          'Draw the little red marks on the vertical axis.>>
          e.Graphics.DrawLine(myPen, 95, startY, 105, startY)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 15 Arial Font.>>
          Dim myFont As New Font("Arial", 15)
          'Draws the strings Level1 to Level4 within the FOR NEXT loop.>>
          e.Graphics.DrawString("Level" & num.ToString, myFont, myBrush, 10, startY)

          myPen = New Pen(Color.LightGray)
          'Draw horizontal graph lines.>>
          e.Graphics.DrawLine(myPen, 100, startY, Me.Width, startY)
        Next

        'I will deliberately not use index zero.>>
        Dim horizontalAxisMarks(60) As Integer
        Dim hSpacing As Integer = (Me.Width - 100) \ 64
        Dim startX As Integer = 100
        For num As Integer = 1 To 60
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startX = startX + hSpacing
          horizontalAxisMarks(num) = startX
          'Draw the little red marks on the horizontal axis.>>
          e.Graphics.DrawLine(myPen, startX, Me.Height - 70, startX, Me.Height - 80)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 10 Arial Font.>>
          Dim myFont As New Font("Arial", 10)
          'Draws the even number strings 2 to 60 within the FOR NEXT loop.>>
          If num Mod 2 = 0 Then
            e.Graphics.DrawString(num.ToString, myFont, myBrush, startX, Me.Height - 70)
          End If

          myPen = New Pen(Color.LightGray)
          'Draw vertical graph lines.>>
          e.Graphics.DrawLine(myPen, startX, 0, startX, Me.Height - 75)
        Next

        'Four fictional levels.>>
        Dim levels() As Integer = {1, 2, 3, 4}
        'Four fictional time intervals.>>
        Dim intervals() As Integer = {4, 22, 26, 60}

        Dim myPoints(4) As Point
        For num = 0 To 3
          myPoints(num).X = horizontalAxisMarks(intervals(num))
          myPoints(num).Y = verticalAxisMarks(levels(num))
        Next
        myPoints(4) = New Point(100, Me.Height - 75)

        'Draw four lines for the graph in different colors.>>
        e.Graphics.DrawLine(New Pen(Color.Red, 4), myPoints(0), myPoints(1))
        e.Graphics.DrawLine(New Pen(Color.Green, 4), myPoints(1), myPoints(2))
        e.Graphics.DrawLine(New Pen(Color.Blue, 4), myPoints(2), myPoints(3))
        e.Graphics.DrawLine(New Pen(Color.Yellow, 4), myPoints(0), myPoints(4))

      End Sub

    End Class


    .--- --- .... -.



    Show off lol
    Seriously though, John, that's exellent!
    Allan
  • Thursday, September 04, 2008 3:40 PM
     
     
    bigamee said:

    Show off lol
    Seriously though, John, that's exellent!
    Allan


    Hi Allan,

    Say in a Little Britain character voice "Yeah, I know!!"   ...LOL!!  :-)

    I have just tried it at 800 X 600 screen resolution as well as at 1280 X 1024, my PC and graphics card and monitor combination has 8 in-between resolutions, I'm not trying them all.  LOL!! ;-)


    Regards,

    John


    .--- --- .... -.
  • Thursday, September 04, 2008 4:10 PM
     
      Has Code
    Option Strict On

    Public Class Form1

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.WindowState = FormWindowState.Maximized
        Me.BackColor = Color.Black

      End Sub

      Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        Dim myPen As New Pen(Color.White)
        'Draw the vertical axis.>>
        e.Graphics.DrawLine(myPen, 100, 0, 100, Me.Height - 75)
        'Draw the horizontal axis.>>
        e.Graphics.DrawLine(myPen, 100, Me.Height - 75, Me.Width, Me.Height - 75)

        'I will deliberately not use index zero.>>
        Dim verticalAxisMarks(4) As Integer
        Dim vSpacing As Integer = (Me.Height - 75) \ 5
        Dim startY As Integer = Me.Height - 75
        For num As Integer = 1 To 4
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startY = startY - vSpacing
          verticalAxisMarks(num) = startY
          'Draw the little red marks on the vertical axis.>>
          e.Graphics.DrawLine(myPen, 95, startY, 105, startY)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 15 Arial Font.>>
          Dim myFont As New Font("Arial", 15)
          'Draws the strings Level1 to Level4 within the FOR NEXT loop.>>
          e.Graphics.DrawString("Level" & num.ToString, myFont, myBrush, 10, startY)

          myPen = New Pen(Color.LightGray)
          'Draw horizontal graph lines.>>
          e.Graphics.DrawLine(myPen, 100, startY, Me.Width, startY)
        Next

        'I will deliberately not use index zero.>>
        Dim horizontalAxisMarks(60) As Integer
        Dim hSpacing As Integer = (Me.Width - 100) \ 64
        Dim startX As Integer = 100
        For num As Integer = 1 To 60
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startX = startX + hSpacing
          horizontalAxisMarks(num) = startX
          'Draw the little red marks on the horizontal axis.>>
          e.Graphics.DrawLine(myPen, startX, Me.Height - 70, startX, Me.Height - 80)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 10 Arial Font.>>
          Dim myFont As New Font("Arial", 10)
          'Draws the even number strings 2 to 60 within the FOR NEXT loop.>>
          If num Mod 2 = 0 Then
            e.Graphics.DrawString(num.ToString, myFont, myBrush, startX, Me.Height - 70)
          End If

          myPen = New Pen(Color.LightGray)
          'Draw vertical graph lines.>>
          e.Graphics.DrawLine(myPen, startX, 0, startX, Me.Height - 75)
        Next

        'Four fictional levels.>>
        Dim levels() As Integer = {1, 2, 3, 4}
        'Four fictional time intervals.>>
        Dim intervals() As Integer = {4, 22, 26, 60}

        Dim myPoints(4) As Point
        For num = 0 To 3
          myPoints(num).X = horizontalAxisMarks(intervals(num))
          myPoints(num).Y = verticalAxisMarks(levels(num))
        Next
        myPoints(4) = New Point(100, Me.Height - 75)

        'Draw four lines for the graph in different colors.>>
        e.Graphics.DrawLine(New Pen(Color.Red, 4), myPoints(0), myPoints(1))
        e.Graphics.DrawLine(New Pen(Color.Green, 4), myPoints(1), myPoints(2))
        e.Graphics.DrawLine(New Pen(Color.Blue, 4), myPoints(2), myPoints(3))
        e.Graphics.DrawLine(New Pen(Color.Yellow, 4), myPoints(0), myPoints(4))

      End Sub

    End Class


    Sir this code has an error in line 76,77 and 78, it saya that the "num" declared, should I declare it?? thank you!!
  • Thursday, September 04, 2008 4:17 PM
     
      Has Code
    Sir I tried your code but there is a error in line 76,77 and 78, it says that the "num" is not declared..
    I tried to declare it but there is another error. Im using the VB.NET 2005 express edition.
  • Thursday, September 04, 2008 11:10 PM
     
     Proposed Has Code
    Hi Al-al,

    Changed the earlier posts as it is here too.
    It should now work with all of the 2005 versions.>>




    Regards,

    John
    _________________________________




    Option Strict On

    Public Class Form1

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.WindowState = FormWindowState.Maximized
        Me.BackColor = Color.Black

      End Sub

      Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        Dim myPen As New Pen(Color.White)
        'Draw the vertical axis.>>
        e.Graphics.DrawLine(myPen, 100, 0, 100, Me.Height - 75)
        'Draw the horizontal axis.>>
        e.Graphics.DrawLine(myPen, 100, Me.Height - 75, Me.Width, Me.Height - 75)

        'I will deliberately not use index zero.>>
        Dim verticalAxisMarks(4) As Integer
        Dim vSpacing As Integer = (Me.Height - 75) \ 5
        Dim startY As Integer = Me.Height - 75
        For num As Integer = 1 To 4
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startY = startY - vSpacing
          verticalAxisMarks(num) = startY
          'Draw the little red marks on the vertical axis.>>
          e.Graphics.DrawLine(myPen, 95, startY, 105, startY)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 15 Arial Font.>>
          Dim myFont As New Font("Arial", 15)
          'Draws the strings Level1 to Level4 within the FOR NEXT loop.>>
          e.Graphics.DrawString("Level" & num.ToString, myFont, myBrush, 10, startY)

          myPen = New Pen(Color.LightGray)
          'Draw horizontal graph lines.>>
          e.Graphics.DrawLine(myPen, 100, startY, Me.Width, startY)
        Next

        'I will deliberately not use index zero.>>
        Dim horizontalAxisMarks(60) As Integer
        Dim hSpacing As Integer = (Me.Width - 100) \ 64
        Dim startX As Integer = 100
        For num As Integer = 1 To 60
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startX = startX + hSpacing
          horizontalAxisMarks(num) = startX
          'Draw the little red marks on the horizontal axis.>>
          e.Graphics.DrawLine(myPen, startX, Me.Height - 70, startX, Me.Height - 80)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 10 Arial Font.>>
          Dim myFont As New Font("Arial", 10)
          'Draws the even number strings 2 to 60 within the FOR NEXT loop.>>
          If num Mod 2 = 0 Then
            e.Graphics.DrawString(num.ToString, myFont, myBrush, startX, Me.Height - 70)
          End If

          myPen = New Pen(Color.LightGray)
          'Draw vertical graph lines.>>
          e.Graphics.DrawLine(myPen, startX, 0, startX, Me.Height - 75)
        Next

        'Four fictional levels.>>
        Dim levels() As Integer = {1, 2, 3, 4}
        'Four fictional time intervals.>>
        Dim intervals() As Integer = {4, 22, 26, 60}

        Dim myPoints(4) As Point
        For num As Integer = 0 To 3
          myPoints(num).X = horizontalAxisMarks(intervals(num))
          myPoints(num).Y = verticalAxisMarks(levels(num))
        Next
        myPoints(4) = New Point(100, Me.Height - 75)

        'Draw four lines for the graph in different colors.>>
        e.Graphics.DrawLine(New Pen(Color.Red, 4), myPoints(0), myPoints(1))
        e.Graphics.DrawLine(New Pen(Color.Green, 4), myPoints(1), myPoints(2))
        e.Graphics.DrawLine(New Pen(Color.Blue, 4), myPoints(2), myPoints(3))
        e.Graphics.DrawLine(New Pen(Color.Yellow, 4), myPoints(0), myPoints(4))

      End Sub

    End Class


    .--- --- .... -.
    • Edited by John Anthony Oliver Thursday, September 04, 2008 11:14 PM Added a bit of text.
    • Proposed As Answer by bigamee Friday, September 05, 2008 5:12 AM
    • Marked As Answer by Al-al Friday, September 05, 2008 2:26 PM
    • Unmarked As Answer by Al-al Friday, September 05, 2008 3:46 PM
    •  
  • Thursday, September 04, 2008 11:42 PM
     
     
    Al-al said:

    Sir I tried your code but there is a error in line 76,77 and 78, it says that the "num" is not declared..
    I tried to declare it but there is another error. Im using the VB.NET 2005 express edition.


    Hi Al-al,

    Get the latest 2008 version here.>>

    http://www.microsoft.com/express/vb/Default.aspx




    Regards,

    John


    .--- --- .... -.
  • Friday, September 05, 2008 4:55 AM
     
     
    Al-al said:

    Option Strict On

    Public Class Form1

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.WindowState = FormWindowState.Maximized
        Me.BackColor = Color.Black

      End Sub

      Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

        Dim myPen As New Pen(Color.White)
        'Draw the vertical axis.>>
        e.Graphics.DrawLine(myPen, 100, 0, 100, Me.Height - 75)
        'Draw the horizontal axis.>>
        e.Graphics.DrawLine(myPen, 100, Me.Height - 75, Me.Width, Me.Height - 75)

        'I will deliberately not use index zero.>>
        Dim verticalAxisMarks(4) As Integer
        Dim vSpacing As Integer = (Me.Height - 75) \ 5
        Dim startY As Integer = Me.Height - 75
        For num As Integer = 1 To 4
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startY = startY - vSpacing
          verticalAxisMarks(num) = startY
          'Draw the little red marks on the vertical axis.>>
          e.Graphics.DrawLine(myPen, 95, startY, 105, startY)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 15 Arial Font.>>
          Dim myFont As New Font("Arial", 15)
          'Draws the strings Level1 to Level4 within the FOR NEXT loop.>>
          e.Graphics.DrawString("Level" & num.ToString, myFont, myBrush, 10, startY)

          myPen = New Pen(Color.LightGray)
          'Draw horizontal graph lines.>>
          e.Graphics.DrawLine(myPen, 100, startY, Me.Width, startY)
        Next

        'I will deliberately not use index zero.>>
        Dim horizontalAxisMarks(60) As Integer
        Dim hSpacing As Integer = (Me.Width - 100) \ 64
        Dim startX As Integer = 100
        For num As Integer = 1 To 60
          'A red pen with a width of 5.>>
          myPen = New Pen(Color.Red, 5)
          startX = startX + hSpacing
          horizontalAxisMarks(num) = startX
          'Draw the little red marks on the horizontal axis.>>
          e.Graphics.DrawLine(myPen, startX, Me.Height - 70, startX, Me.Height - 80)

          'Create a yellow SolidBrush.>>
          Dim myBrush As New SolidBrush(Color.Yellow)
          'Create a size 10 Arial Font.>>
          Dim myFont As New Font("Arial", 10)
          'Draws the even number strings 2 to 60 within the FOR NEXT loop.>>
          If num Mod 2 = 0 Then
            e.Graphics.DrawString(num.ToString, myFont, myBrush, startX, Me.Height - 70)
          End If

          myPen = New Pen(Color.LightGray)
          'Draw vertical graph lines.>>
          e.Graphics.DrawLine(myPen, startX, 0, startX, Me.Height - 75)
        Next

        'Four fictional levels.>>
        Dim levels() As Integer = {1, 2, 3, 4}
        'Four fictional time intervals.>>
        Dim intervals() As Integer = {4, 22, 26, 60}

        Dim myPoints(4) As Point
        For num = 0 To 3
          myPoints(num).X = horizontalAxisMarks(intervals(num))
          myPoints(num).Y = verticalAxisMarks(levels(num))
        Next
        myPoints(4) = New Point(100, Me.Height - 75)

        'Draw four lines for the graph in different colors.>>
        e.Graphics.DrawLine(New Pen(Color.Red, 4), myPoints(0), myPoints(1))
        e.Graphics.DrawLine(New Pen(Color.Green, 4), myPoints(1), myPoints(2))
        e.Graphics.DrawLine(New Pen(Color.Blue, 4), myPoints(2), myPoints(3))
        e.Graphics.DrawLine(New Pen(Color.Yellow, 4), myPoints(0), myPoints(4))

      End Sub

    End Class


    Sir this code has an error in line 76,77 and 78, it saya that the "num" declared, should I declare it?? thank you!!



    Hi al-al
    I see no problem with the program - num is declared - it is the loop control variable as I've indicated in text highlighted in green.
    Allan

  • Friday, September 05, 2008 7:55 AM
     
      Has Code
    bigamee said:


    Hi al-al
    I see no problem with the program - num is declared - it is the loop control variable as I've indicated in text highlighted in green.
    Allan

    Hi Allan,

    I reckon the problem may have been the third FOR NEXT loop.

        For num = 0 To 3
          myPoints(num).X = horizontalAxisMarks(intervals(num))
          myPoints(num).Y = verticalAxisMarks(levels(num))
        Next

    'instead of.>>

        For num As Integer = 0 To 3
          myPoints(num).X = horizontalAxisMarks(intervals(num))
          myPoints(num).Y = verticalAxisMarks(levels(num))
        Next


    As I no longer have 2005 installed ( any version ) it is my educated deduction ( not a guess ).

    LOL!!


    Regards,

    John


    .--- --- .... -.
  • Friday, September 05, 2008 2:25 PM
     
     
    To sir John Anthony Oliver and Sir bigamee.

    HI guys!

    Thank you very much for your help, as of now I'm going to integrate the graph to my system hope that it would work properly.. if ever i have another question please be there to answer my question again.. thank you very much..
  • Friday, September 05, 2008 3:59 PM
     
      Has Code
    Sir!

    Gud day!

    You have answered my previous question and i am very thankful for that. but now i have another question for you guys.. how can I put the data of my main form to your graph? can your graph and my form be integrated and share common resources of data?? here is my main form and I already assign the water level to the value of "Stat.Text" the line that has a yellow markings, and also is this possible that your graph could display like the one in task manager? like when the water level is only in level 1 it would travel only in that level thus creating a straight path on that level  only like in the task manager and waiting for another level to occur??

    Public Class Form1

        Dim status As Boolean = False

     

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

            If (status = False) Then

                Timer1.Enabled = True

                status = True

                Button2.Text = "De-Activate!"

                Button2.BackColor = Color.Red

     

            Else

                Timer1.Enabled = False

                status = False

                Button2.Text = "Activate"

                Button2.BackColor = Color.DarkGreen

            End If

        End Sub

     

        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

            Dim intAddress As Integer, intReadVal As Integer

            intAddress = 889

            intReadVal = Porting.Inp(intAddress)

            Stat.Text = intReadVal.ToString()

     

     

        End Sub

     

        Private Sub Stat_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Stat.TextChanged

            Dim file As String = soundBox.Text

            Dim graph As Form = New Graph

            If Stat.Text = 126 Then

     

     

            ElseIf Stat.Text = 62 Then 'port 10 = level 1

                PlaySound(file, 0, 1)

                graph.Show()

     

            ElseIf Stat.Text = 190 Then 'port 11 = level 2

                PlaySound(file, 0, 1)

                graph.Show()

     

            ElseIf Stat.Text = 158 Then 'port 12 = level 3

                PlaySound(file, 0, 1)

                graph.Show()

     

            ElseIf Stat.Text = 150 Then 'port 15 = level 4

                PlaySound(file, 0, 1)

                graph.Show()

     

            End If

        End Sub

     

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

            Dim fn As String = ""

            Dim path As String = ""

            Dim file As String = ""

     

            If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then

     

                fn = System.IO.Path.GetFileName(OpenFileDialog1.FileName)

                path = System.IO.Path.GetDirectoryName(OpenFileDialog1.FileName)

                file = path + "\\" + fn

     

                soundBox.Text = file

                soundBox.Items.Add(file)

            End If

        End Sub

    End Class


  • Saturday, September 06, 2008 12:20 AM
     
     
    Hi Al-al,

    I you meaning a moving graph like the Performance or Networking graphs you see in Task Manager?

    Some of the code you have posted I do not recognise.

    Are you using the ZedGraph component you mentioned in another thread?


    Regards,

    John


    .--- --- .... -.
  • Saturday, September 06, 2008 3:28 PM
     
      Has Code
    HI Sir John,

    I you meaning a moving graph like the Performance or Networking graphs you see in Task Manager?

    yes, it is?? could you please help me about that??

    I,m not using the zedgraph co'z i don't understand how the zedgraph works.. i create this code in VB.NET 2005 express edition, and its function is to detect the port status of my PC using the parallel port(DB25), now the function of this code is whenever you activated it, its timer will enable and will start to wait for an event to happen and every time an event happen its port status will changed, those that i highlighted with color yellow are the port status of my PC, and in your PC it might not the same with mine because we are using different brand of board, thats the explanation I learned upon my research regarding the "porting", and this code of mine is using a improvised hardware(IM using a remote control car)and its control instead of the left,right,forward,back, I changed them into water sensors as you can imagine evry time those control be trigered like the left button it will be interpreted by my code as the level 1: which is the port 10 with port status  = 62, level 2: right button is the port 11 with port status = 190, level 3: forward button is the port 12 with port status = 158, and level 4: back button is the port 15 with port status of 150, (they were highlighted codes, yellow), and evrytime this button/sensors be trigered it will load your graph,, by the way I edited the name of your graph sorry for that i only wanted it to be named as "graph.vb" hope its ok with you hehehe, and now my prob is that how am i going to use those data to send it to your graph?so that your graph will plot the point according to my sensors..

    Thank you!!
  • Thursday, September 11, 2008 1:54 PM
     
      Has Code
    Al-al said:

    HI Sir John,

    I you meaning a moving graph like the Performance or Networking graphs you see in Task Manager?

    yes, it is?? could you please help me about that??

    I,m not using the zedgraph co'z i don't understand how the zedgraph works.. i create this code in VB.NET 2005 express edition, and its function is to detect the port status of my PC using the parallel port(DB25), now the function of this code is whenever you activated it, its timer will enable and will start to wait for an event to happen and every time an event happen its port status will changed, those that i highlighted with color yellow are the port status of my PC, and in your PC it might not the same with mine because we are using different brand of board, thats the explanation I learned upon my research regarding the "porting", and this code of mine is using a improvised hardware(IM using a remote control car)and its control instead of the left,right,forward,back, I changed them into water sensors as you can imagine evry time those control be trigered like the left button it will be interpreted by my code as the level 1: which is the port 10 with port status  = 62, level 2: right button is the port 11 with port status = 190, level 3: forward button is the port 12 with port status = 158, and level 4: back button is the port 15 with port status of 150, (they were highlighted codes, yellow), and evrytime this button/sensors be trigered it will load your graph,, by the way I edited the name of your graph sorry for that i only wanted it to be named as "graph.vb" hope its ok with you hehehe, and now my prob is that how am i going to use those data to send it to your graph?so that your graph will plot the point according to my sensors..

    Thank you!!


    HI there!

    guys can anyone out there could help me regarding this matter??
    hope that anybody or somebody could help me with this..
    to all that happen to answer my question and give me a good advice,,

    I thank you guys!!! you've help me a lot!!!

     

  • Thursday, September 11, 2008 3:07 PM
     
     
     Hi Al-al
    IIRC John's graph routine plots data held in a small array.  Have your application write the data appropriately to the array and then call John's routine. You may have to do something like making the array global in a module, or write to the array using namespace and form names etc., if you want to share data via the array. What I'm saying is that in effect, John has already done the work for you, all you have to do now is get your data into the array that John's routine uses and you're good to go :)
    Allan

    • Edited by bigamee Thursday, September 11, 2008 3:10 PM spelling
    •  
  • Friday, September 12, 2008 6:09 AM
     
     
    bigamee said:

     Hi Al-al
    IIRC John's graph routine plots data held in a small array.  Have your application write the data appropriately to the array and then call John's routine. You may have to do something like making the array global in a module, or write to the array using namespace and form names etc., if you want to share data via the array. What I'm saying is that in effect, John has already done the work for you, all you have to do now is get your data into the array that John's routine uses and you're good to go :)
    Allan


    Ahh, ok

    thank for that idea,,
    am can you give me some code fragment regarding on your suggestion??
    sory for my request but I couldnt figured that out without sample codes in which i can test how it will work,,
    thank you!!!,
  • Friday, September 12, 2008 1:12 PM
     
     
    Hi again Al al,

    Sorry for not adding to this thread but I don't know how to scroll the contents of a FORM or a PictureBox to create a moving graph effect in the way that you would like on a "PC" computer.

    I can move a PictureBox so that it looks like a scroll effect but it would not show constantly changing data from a parallel or serial port interface.

    Now if Allan or anyone else knows how and where a PictureBox image is held in memory bit-wise per pixel I could move that image within the PictureBox using assembly language "machine code" if I knew PC assembly language mnemonics too, which I don't. I don't even have an assembler.

    If the image is as sequential bytes per each primary colour of red, green and blue then a ASL or
    Arithmetic Shift Left followed by inserting the bit value from position 8 of the byte to the right into position zero of the current byte ( for each row ) would work to scroll the picture left.
    You could use ROL or Rotate Left from the right-most byte of each row working to the left too which would be easier.

    I have done similar code on an old 8 bit computer.

    There may be API functions to scroll an image in memory left, right, up and down?


    Regards,

    John

    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
  • Friday, September 12, 2008 3:20 PM
     
     
    John Anthony Oliver said:

    Hi again Al al,

    Sorry for not adding to this thread but I don't know how to scroll the contents of a FORM or a PictureBox to create a moving graph effect in the way that you would like on a "PC" computer.

    I can move a PictureBox so that it looks like a scroll effect but it would not show constantly changing data from a parallel or serial port interface.

    Now if Allan or anyone else knows how and where a PictureBox image is held in memory bit-wise per pixel I could move that image within the PictureBox using assembly language "machine code" if I knew PC assembly language mnemonics too, which I don't. I don't even have an assembler.

    If the image is as sequential bytes per each primary colour of red, green and blue then a ASL or
    Arithmetic Shift Left followed by inserting the bit value from position 8 of the byte to the right into position zero of the current byte ( for each row ) would work to scroll the picture left.
    You could use ROL or Rotate Left from the right-most byte of each row working to the left too which would be easier.

    I have done similar code on an old 8 bit computer.

    There may be API functions to scroll an image in memory left, right, up and down?


    Regards,

    John


    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835

    Thank you for that hehehe,
    sory for bothering you much regarding my prob,, nwei thank you for all that you've done i really appreciate it and thanks for the link.. if ever i made it to the real time graph i will post it again here.. hope I can able to make it!!! my idea is that some "for loops and a timer" would do but i'm still working on it...

  • Friday, September 12, 2008 4:21 PM
     
     
    John Anthony Oliver said:

    Hi again Al al,

    Sorry for not adding to this thread but I don't know how to scroll the contents of a FORM or a PictureBox to create a moving graph effect in the way that you would like on a "PC" computer.

    I can move a PictureBox so that it looks like a scroll effect but it would not show constantly changing data from a parallel or serial port interface.

    Now if Allan or anyone else knows how and where a PictureBox image is held in memory bit-wise per pixel I could move that image within the PictureBox using assembly language "machine code" if I knew PC assembly language mnemonics too, which I don't. I don't even have an assembler.

    If the image is as sequential bytes per each primary colour of red, green and blue then a ASL or
    Arithmetic Shift Left followed by inserting the bit value from position 8 of the byte to the right into position zero of the current byte ( for each row ) would work to scroll the picture left.
    You could use ROL or Rotate Left from the right-most byte of each row working to the left too which would be easier.

    I have done similar code on an old 8 bit computer.

    There may be API functions to scroll an image in memory left, right, up and down?


    Regards,

    John




    Hi John
    I do or did have a VB6 graph that did scroll continously and as data was being updated. Forgetting the vb6 thing how would I do it in vb.net?
    I would grab the portion of the rectangle that I currently want to keep as a bitmap and add to. Make that bitmap the new image of the picture, effectively moving the left edge of that new image to the left edge of the picturebox and append drawing of the new data to the end. I'll see if I can explain it graphically on here using text.


    --------------------------------------------------------
    |    |                                                              |
    |    |Region to grab /\/\/\/\/\/\/\/\/\/\/\ /\/\/\/ |
    |    |                                                              |
    --------------------------------------------------------

    --------------------------------------------------------
    |                                                              |    |
    |Region to grab   /\/\/\/\/\/\/\/\/\/\/\/\/\/\ |    |     Make the captured image region the new picturebox  image - note the scroll left effect
    |                                                              |    |    and the small blank region to the right. We write the new data there.
    --------------------------------------------------------



    to give:

    --------------------------------------------------------
    |                                                              |    |
    |Region to grab   /\/\/\/\/\/\/\/\/\/\/\/\/\/\ /\/ |    
    |                                                              |    |
    --------------------------------------------------------

    Hope you can see what I'm getting at - it would mean making sure that the picturebox remains a constant size rather than autosizing. Without direct access to video memory I can't see another way of doing it. There's a little project for you to code John  ;)
    Allan
  • Friday, September 12, 2008 4:42 PM
     
     
    bigamee said:


    Hi John
    I do or did have a VB6 graph that did scroll continously and as data was being updated. Forgetting the vb6 thing how would I do it in vb.net?
    I would grab the portion of the rectangle that I currently want to keep as a bitmap and add to. Make that bitmap the new image of the picture, effectively moving the left edge of that new image to the left edge of the picturebox and append drawing of the new data to the end. I'll see if I can explain it graphically on here using text.

    Hope you can see what I'm getting at - it would mean making sure that the picturebox remains a constant size rather than autosizing. Without direct access to video memory I can't see another way of doing it. There's a little project for you to code John  ;)
    Allan



    Hi Allan,

    If you ever find your VB6 project then email to me the code please.
    I might be able to convert it. :-)

    Scrolling could be done a pixel at a time.

    I know exactly what you mean.

    I will try and experiment a little later on with the IMAGE of a PictureBox or its BackGroundImage, I am at work later from 7pm till 10pm. I am going to get a quick bite now ( maybe fish-finger-sandwiches "sarnies" again, HOVIS SEED SENSATIONS bread is gorgeous for them ;-) ).

    I am also thinking of REGIONs and RECTANGLEs but I don't think that is the way to go.

    Maybe, I might have to write an EXTENSION METHOD or / and a custom TRANSFORM ( if possible ).

    I will post code in this thread if I have any success.


    Regards,

    John.


    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
    • Edited by John Anthony Oliver Friday, September 12, 2008 4:49 PM Spelling corrected and some grammar.
    •  
  • Friday, September 12, 2008 5:05 PM
     
     
    John Anthony Oliver said:

    bigamee said:

    John Anthony Oliver said:

    Hi again Al al,

    Sorry for not adding to this thread but I don't know how to scroll the contents of a FORM or a PictureBox to create a moving graph effect in the way that you would like on a "PC" computer.

    I can move a PictureBox so that it looks like a scroll effect but it would not show constantly changing data from a parallel or serial port interface.

    Now if Allan or anyone else knows how and where a PictureBox image is held in memory bit-wise per pixel I could move that image within the PictureBox using assembly language "machine code" if I knew PC assembly language mnemonics too, which I don't. I don't even have an assembler.

    If the image is as sequential bytes per each primary colour of red, green and blue then a ASL or
    Arithmetic Shift Left followed by inserting the bit value from position 8 of the byte to the right into position zero of the current byte ( for each row ) would work to scroll the picture left.
    You could use ROL or Rotate Left from the right-most byte of each row working to the left too which would be easier.

    I have done similar code on an old 8 bit computer.

    There may be API functions to scroll an image in memory left, right, up and down?


    Regards,

    John




    Hi John
    I do or did have a VB6 graph that did scroll continously and as data was being updated. Forgetting the vb6 thing how would I do it in vb.net?
    I would grab the portion of the rectangle that I currently want to keep as a bitmap and add to. Make that bitmap the new image of the picture, effectively moving the left edge of that new image to the left edge of the picturebox and append drawing of the new data to the end. I'll see if I can explain it graphically on here using text.

    Hope you can see what I'm getting at - it would mean making sure that the picturebox remains a constant size rather than autosizing. Without direct access to video memory I can't see another way of doing it. There's a little project for you to code John  ;)
    Allan



    Hi Allan,

    If you ever find your VB6 project then email to me the code please.
    I might be able to convert it. :-)

    Scrolling could be done a pixel at a time.

    I know exactly what you mean.

    I will try and experiment a little later on with the IMAGE of a PictureBox or its BackGroundImage, I am at work later from 7pm till 10pm. oing to get a quick bite now ( maybe fish-finger-sandwiches "sarnies" again, HOVIS SEED SENSATIONS bread is grgeous for them ;-) ).

    I am also thinking of REGIONs and RECTANGLEs but I don't think tat is the way to go.

    Maybe, I might have to write an EXTENSION METHOD for a custom TRANSFORM ( if possible ).

    I will post code in this thread if I have any success.


    Regards,

    John.


    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835

    hey guys!!

    thank you again for your help!!!




  • Friday, September 12, 2008 5:07 PM
    Moderator
     
     
    For a scrolling graph, simply store a timestamp with each data point. position the X-value of that point based on your time span of the X axis of your graph.


    Stephen J Whiteley
  • Friday, September 12, 2008 6:25 PM
     
     
    Hi John
     I cant find the actual vb6 program I was thinking of - it must be on the other PC somwehere. But it was based on this following MSDN article for a dynamically scrolling graph:
    Allan

     

    HOWTO: Create a Dynamically Scrolling Graph

    --------------------------------------------------------------------------------
    The information in this article applies to:

    Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0

    --------------------------------------------------------------------------------


    SUMMARY
    This article shows you how to create a dynamically scrolling graph in Visual Basic. You can use the information in this article to create a graph as data is generated, such as in a monitoring program.



     

    MORE INFORMATION
    The sample project uses Timer and PictureBox controls. The graph is first created in memory and then copied to the PictureBox control using the BitBlt function. This method is used to allow the PictureBox control to update properly when another window partially or completely covers the PictureBox control.

    The next section shows you how to create the sample project.


    To Create the Sample Project
    Start a new Standard EXE project in Visual Basic. Form1 is created by default.


    Add a Timer and a PictureBox control to Form1.


    Copy the following code to the Code window of Form1:

          Option Explicit
          Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
          Private Const PS_SOLID = 0

          Private Declare Function CreateCompatibleDC Lib "gdi32" _
                         (ByVal hdc As Long) As Long

          Private Declare Function CreateCompatibleBitmap Lib "gdi32" _
                         (ByVal hdc As Long, _
                         ByVal nWidth As Long, _
                         ByVal nHeight As Long) As Long

          Private Declare Function SelectObject Lib "gdi32" _
                         (ByVal hdc As Long, _
                         ByVal hObject As Long) As Long

          Private Declare Function CreatePen Lib "gdi32" _
                         (ByVal nPenStyle As Long, _
                         ByVal nWidth As Long, _
                         ByVal crColor As Long) As Long

          Private Declare Function LineTo Lib "gdi32" _
                         (ByVal hdc As Long, _
                         ByVal x As Long, _
                         ByVal y As Long) As Long

          Private Declare Function MoveToEx Lib "gdi32" _
                         (ByVal hdc As Long, _
                         ByVal x As Long, _
                         ByVal y As Long, _
                         ByVal lpPoint As Long) As Long

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

    Private Const pWidth = 250    ' Width of picture box in pixels.
          Private Const pHeight = 150   ' Height of picture box in pixels.
          Private Const pGrid = 25      ' Distance between grid lines.
          Private Const tInterval = 100 ' Interval between timer samplings
                                        ' in milliseconds.
          Private Const pHeightHalf = pHeight \ 2
          Dim counter As Long  ' Number of data points logged so far. Used to
                               ' sync grid.
          Dim oldY As Long     ' Contains the previous y coordinate.
          Dim hDCh As Long, hPenB As Long, hPenC As Long

          Private Sub Form_Load()
              Dim hBmp As Long
              Dim i As Integer
              Me.Show
              Picture1.ScaleMode = 3
              Picture1.Left = 0
              Picture1.Top = 0
              Form1.ScaleMode = 3
              Picture1.Height = 155
              Picture1.Width = 255
              counter = 0
              hDCh = CreateCompatibleDC(Picture1.hdc)
              hBmp = CreateCompatibleBitmap(Picture1.hdc, _
                                           pWidth, _
                                           pHeight)
              Call SelectObject(hDCh, hBmp)
              hPenB = CreatePen(PS_SOLID, 0, vbBlack)
              hPenC = CreatePen(PS_SOLID, 0, vbRed)
              Call SelectObject(hDCh, hPenB)

          ' Plot horizontal grid lines.
              For i = pGrid To pHeight - 1 Step pGrid
                  Picture1.Line (0, i)-(pWidth, i)
              Next

          ' Plot vertical grid lines.
              For i = pGrid - (counter Mod pGrid) To _
                               pWidth - 1 Step pGrid
                  Picture1.Line (i, 0)-(i, pHeight)
              Next

              Call BitBlt(hDCh, _
                         0, _
                         0, _
                         pWidth, _
                         pHeight, _
                         Picture1.hdc, _
                         0, _
                         0, _
                         SRCCOPY)
              Timer1.Interval = 100
              Timer1.Enabled = True
              oldY = pHeightHalf
          End Sub

          Private Sub Timer1_Timer()
              Dim i As Integer
              Call BitBlt(hDCh, _
                            0, _
                            0, _
                            pWidth - 1, _
                            pHeight, _
                            hDCh, _
                            1, _
                            0, _
                            SRCCOPY)

              If counter Mod pGrid = 0 Then
                  Call MoveToEx(hDCh, pWidth - 2, 0, 0)
                  Call LineTo(hDCh, pWidth - 2, pHeight)
              End If

              i = Sin(0.1 * counter) * _
                   (pHeightHalf - 1) + _
                   pHeightHalf

              Call SelectObject(hDCh, hPenC)
              Call MoveToEx(hDCh, pWidth - 3, oldY, 0)
              Call LineTo(hDCh, pWidth - 2, i)
              Call SelectObject(hDCh, hPenB)
              Call BitBlt(Picture1.hdc, _
                            0, _
                            0, _
                            pWidth, _
                            pHeight, _
                            hDCh, _
                            0, _
                            0, _
                            SRCCOPY)
              counter = counter + 1
              oldY = i
          End Sub
     



     

    From the Run menu, click Start or press the F5 key to start the program. A sine wave in red is displayed in the PictureBox control.


     

  • Saturday, September 13, 2008 4:35 AM
     
     
    John. if you're online I posted a vb6 dyamically scrolling graph article.
    Allan
  • Saturday, September 13, 2008 4:54 AM
     
     
    Hi Allan,

    Yes I'm online ( I will add you to my MESSENGER contacts so you can see when I'm online and activate it when I am logged into the forums too ) but you might as well delete that post as it would take some converting.

    Too may conversion errors. Delete it later today though please after I have grabbed the code. ;-)

    E.G. What is Picture1.Hdc ?

    I know it is something to do with PictureBox1 but what the <insert expletive> is Hdc ?

    I have done a VB.Net PictureBox1 scroll routine on my desktop computer.
    I will post the code I have so far later.
      :-)

    I'm not feeling to good with my neuralgia at this very moment, so painkillers then bed for me right now. It is nearly 5:50am anyway.

    I'm replying on my laptop.

    Email me please if you know how to fix WINDOWS as my desktop keeps giving me browser errors in more than one browser. :-(

    Bad verb, bad request, errors 400 and 500 I think.

    Anyway, its goodnight from me or should that be good morning? ...LOL.


    Regards,


    John

    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835
  • Saturday, September 13, 2008 5:13 AM
     
     
    John Anthony Oliver said:

    Hi Allan,

    Yes I'm online ( I will add you to my MESSENGER contacts so you can see when I'm online and activate it when I am logged into the forums too ) but you might as well delete that post as it would take some converting.

    Too may conversion errors. Delete it later today though please after I have grabbed the code. ;-)

    E.G. What is Picture1.Hdc ?

    I know it is something to do with PictureBox1 but what the <insert expletive> is Hdc ?

    I have done a VB.Net PictureBox1 scroll routine on my desktop computer.
    I will post the code I have so far later.
      :-)

    I'm not feeling to good with my neuralgia at this very moment, so painkillers then bed for me right now. It is nearly 5:50am anyway.

    I'm replying on my laptop.

    Email me please if you know how to fix WINDOWS as my desktop keeps giving me browser errors in more than one browser. :-(

    Bad verb, bad request, errors 400 and 500 I think.

    Anyway, its goodnight from me or should that be good morning? ...LOL.


    Regards,


    John


    For links to VB.Net tutorials see here.>> http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/29f2179b-997b-4115-a96d-a0834853b835



    Yeh I'm off to bed too methinks. Picture1.Hdc is a a kind of handle to the picturebox - a bit like a Hwnd but the 'dc' part means device context and is a pointer providing slightly lower-level access to the control (such as Windows Messages being passed to the control) - viz the following C++ routine:

    case WM_PAINT:
    hDC = BeginPaint(hwnd,&paintStruct);
    /* Set txt color to blue*/
    SetTextColor(hDC, COLORREF(0x00FF0000));
    /* Display text in middle of window*/
    TextOut(hDC,150,150,string,sizeof(string)-1);
    EndPaint(hwnd, &paintStruct);
    return 0;
    break;

    Hope you wake up feeling better. Goodnight. I will delete the code later.

    Allan

     

    • Edited by bigamee Saturday, September 13, 2008 10:07 AM spelling
    •  
  • Sunday, September 14, 2008 5:27 PM
     
      Has Code
    'Option Strict On

    Public Class Graph
        Inherits System.Windows.Forms.Form
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            'Me.WindowState = FormWindowState.Maximized
            Me.BackColor = Color.Black

        End Sub

        Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

            Dim myPen As New Pen(Color.White)
            'Draw the vertical axis.>>
            e.Graphics.DrawLine(myPen, 100, 0, 100, Me.Height - 75)
            'Draw the horizontal axis.>>
            e.Graphics.DrawLine(myPen, 100, Me.Height - 75, Me.Width, Me.Height - 75)

            'I will deliberately not use index zero.>>
            Dim verticalAxisMarks(4) As Integer
            Dim vSpacing As Integer = (Me.Height - 75) \ 5
            Dim startY As Integer = Me.Height - 75

            For num As Integer = 1 To 4

                'A red pen with a width of 5.>>
                myPen = New Pen(Color.Red, 5)
                startY = startY - vSpacing
                verticalAxisMarks(num) = startY
                'Draw the little red marks on the vertical axis.>>
                e.Graphics.DrawLine(myPen, 95, startY, 105, startY)

                'Create a yellow SolidBrush.>>
                Dim myBrush As New SolidBrush(Color.Yellow)
                'Create a size 15 Arial Font.>>
                Dim myFont As New Font("Arial", 15)
                'Draws the strings Level1 to Level4 within the FOR NEXT loop.>>
                e.Graphics.DrawString("Level" & num.ToString, myFont, myBrush, 10, startY)

                myPen = New Pen(Color.LightGray)
                'Draw horizontal graph lines.>>
                e.Graphics.DrawLine(myPen, 100, startY, Me.Width, startY)
            Next

            'I will deliberately not use index zero.>>
            Dim horizontalAxisMarks(60) As Integer
            Dim hSpacing As Integer = (Me.Width - 100) \ 64
            Dim startX As Integer = 100
            For num As Integer = 1 To 60


                'A red pen with a width of 5.>>
                myPen = New Pen(Color.Red, 5)
                startX = startX + hSpacing
                horizontalAxisMarks(num) = startX
                'Draw the little red marks on the horizontal axis.>>
                e.Graphics.DrawLine(myPen, startX, Me.Height - 70, startX, Me.Height - 80)

                'Create a yellow SolidBrush.>>
                Dim myBrush As New SolidBrush(Color.Yellow)
                'Create a size 10 Arial Font.>>
                Dim myFont As New Font("Arial", 5)
                'Draws the even number strings 2 to 60 within the FOR NEXT loop.>>
                If num Mod 2 = 0 Then
                    e.Graphics.DrawString(num.ToString, myFont, myBrush, startX, Me.Height - 70)
                End If

                myPen = New Pen(Color.LightGray)
                'Draw vertical graph lines.>>
                e.Graphics.DrawLine(myPen, startX, 0, startX, Me.Height - 75)
            Next
            'value of y axis
            Dim Font As New Font("Arial", 8)
            Dim Brush As New SolidBrush(Color.Yellow)
            e.Graphics.DrawString("Time(sec)", Font, Brush, startX, Me.Height - 60)
            'Four fictional levels.>>
            Dim levels() As Integer = {} 'level port status

            'levels(0) = main.Stat.Text = 127   
            'levels(1) = main.Stat.Text = 128
            'levels(2) = main.Stat.Text = 158
            'levels(3) = main.Stat.Text = 150

            'If levels(0) = 1 Then
           '  main.Stat.Text = 127
            'ElseIf levels(1) = 2 Then
            '    main.Stat.Text = 128
            'ElseIf levels(2) = 3 Then
            '    main.Stat.Text = 158
            'ElseIf levels(3) = 4 Then
            '    main.Stat.Text = 150
            'End If

            For point As Integer = 0 To 3
                If levels(point) = 1 Then
                    main.Stat.Text = 127           'level 1
                ElseIf levels(point) = 2 Then
                    main.Stat.Text = 128           'level  2
                ElseIf levels(point) = 3 Then
                    main.Stat.Text = 158           'level 3
                ElseIf levels(point) = 4 Then
                    main.Stat.Text = 150           'level 4
                End If
            Next
            'Four fictional time intervals.>>
            Dim intervals() As Integer = {1, 15, 30, 60} 'timer
            Timer1.Enabled = True

            Dim myPoints(4) As Point
            For num As Integer = 0 To 3
                myPoints(num).X = horizontalAxisMarks(intervals(num))
                myPoints(num).Y = verticalAxisMarks(levels(num))
            Next
            myPoints(4) = New Point(100, Me.Height - 75)

            'Draw four lines for the graph in different colors.>>
            e.Graphics.DrawLine(New Pen(Color.Red, 4), myPoints(0), myPoints(1))
            e.Graphics.DrawLine(New Pen(Color.Red, 4), myPoints(1), myPoints(2))
            e.Graphics.DrawLine(New Pen(Color.Red, 4), myPoints(2), myPoints(3))
            e.Graphics.DrawLine(New Pen(Color.Red, 4), myPoints(0), myPoints(4))

        End Sub

    End Class

    ---------------------------

    hi guys!!

    please help me with the code above,, because I'm trying to plot the data on my main.vb i used the code fragment that are highlighted above but there is some difficulty that i am encountering, it is not plotting the point on the graph and there is a run time error that i am encounter "A first chance exception of type 'System.IndexOutOfRangeException' occurred in Flood.exe" can anyone help me solve this error??
    the code above was created by Sir JOHN, and also i add this "Inherits System.Windows.Forms.Form" so that i could used the data in my main .vb which is the "main.Stat.Text"..