Quantcast
Channel: paint event on picturebox
Viewing all articles
Browse latest Browse all 48

paint event on picturebox

$
0
0

Try this code please:

"Other way" unchecked = the graph shows point after point (i do not want this) at the speed set  

"Other way" checked = the graph shows as it should, but it slows down when points are many

Imports System.Math
Public Class Form1
    Dim deltax, deltay, points() As Single
    Dim offset As Single
    Dim x1, yprec, newpoint As Single
    Dim myPen As Pen
    Dim N, i, s As Long

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            i = 0
            show2 = True
        Else
            i = 0
            show2 = False
        End If
    End Sub

    Dim show2 As Boolean
    Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click

    End Sub

    Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint

        If show2 = False Then
            e.Graphics.DrawLine(myPen, x1, yprec, x1 + deltax, newpoint)
            yprec = newpoint
            x1 = x1 + deltax
        Else
            x1 = 0
            yprec = points(0)
            For s = 1 To i - 1
                e.Graphics.DrawLine(myPen, x1, yprec, x1 + deltax, points(s))
                yprec = points(s)
                x1 = x1 + deltax
            Next
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Timer1.Interval = 10
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If show2 = False Then
            newpoint = 0.4 * Sin(0.01 * i) * deltay + offset
            i = i + 1
        Else
            For s = 0 To i
                points(s) = 0.4 * Sin(0.001 * s) * deltay + offset
            Next
            i = i + 1
        End If

        PictureBox1.Invalidate()
    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        N = 1000000
        ReDim points(N)
        myPen = New Pen(Drawing.Color.White, 3)
        deltay = PictureBox1.Height
        deltax = PictureBox1.Width / N
        offset = PictureBox1.Height / 2
        CheckBox1.Text = "Other way"
    End Sub
End Class







Viewing all articles
Browse latest Browse all 48

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>