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

paint event on picturebox

$
0
0

Hi

OK. You are aware that there is a very big difference between storing a large collection of data and trying to displaying it all in this way.

By way of an example, using a simulation of incoming data points.

Try this stand alone example, Use a new Project with a blank Form1 and replace default code with this code.

The example simulates incoming data. It starts off with a small amount (10) and displays a sinusoidal representation along with total number of data points and the incoming (rate).. The incoming rate can be increase by mouse left button click on label (or dec using the mouse right button) When you start to have a large number (nowhere your suggested data point maximum), then the graph becomes totally irrelevant.

The idea is to show that if you have large numbers of data points,it makes no sence to try and display them all as a graph - mush better to just show subsets of points with scroll.

Anyway here is the demo code.

' blank Form1
Option Strict On
Option Explicit On
Public Class Form1
  Dim s As Swv
  Dim d As Single = 1
  Dim WithEvents Lab As New Label
  Dim inc As Single = 0.1D
  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    Size = New Size(800, 600)
    s = New Swv
    With s
      .Width = 760
      .Height = 400
      .Location = New Point(20, 20)
      .Anchor = AnchorStyles.Bottom Or AnchorStyles.Left Or
       AnchorStyles.Right Or AnchorStyles.Top
    End With

    With Lab
      .AutoSize = True
      .Font = New Font("Arial", 22, FontStyle.Bold)
      .Location = New Point(s.Left + 20, s.Bottom + 8)
      .Text = "Pts: " & (d * 100).ToString("0") & "   (" & (inc * 100).ToString("0.0") & ")"
      .BackColor = Color.Yellow
      .BorderStyle = BorderStyle.FixedSingle
    End With
    Controls.AddRange({s, Lab})

    Timer1.Interval = 1000
    Timer1.Enabled = True
  End Sub

  Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    d += inc
    s.Freq = d
    s.Invalidate()
    Lab.Text = "Pts: " & (d * 100).ToString("0") & "   (" & (inc * 100).ToString("0.0") & ")"
  End Sub
  Private Sub Label4_MouseClick(sender As Object, e As MouseEventArgs) Handles Lab.MouseClick
    Select Case e.Button
      Case MouseButtons.Left
        inc += 1
        If inc > 10 Then
          inc = 10
        End If
      Case MouseButtons.Right
        inc -= 1
        If inc < 0 Then
          inc = 0
        End If
    End Select
  End Sub
End Class

Public Class Swv
  Inherits Control
  Dim MF As Single
  Const pi As Single = CSng(Math.PI)
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    Dim HH As Single = Convert.ToSingle(ClientSize.Height / 2) - 3
    e.Graphics.Clear(Color.White)
    e.Graphics.DrawLine(New Pen(Color.Blue, 2), New PointF(0, HH), New PointF(ClientSize.Width, HH))
    Dim points(ClientSize.Width * 2) As PointF
    For i As Integer = 0 To ClientSize.Width * 2
      points(i) = New PointF(CType(i / 2, Single), HH +
       CType(Math.Sin(i * MF * pi / ClientSize.Width) * (HH - 1), Single))
    Next
    e.Graphics.DrawLines(New Pen(Color.Red, 5), points)
  End Sub
  Public Property Freq() As Single
    Get
      Return MF
    End Get
    Set(ByVal value As Single)
      MF = value
    End Set
  End Property
  Sub New()
    SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or
     ControlStyles.UserPaint Or ControlStyles.ResizeRedraw, True)
    UpdateStyles()
  End Sub
End Class


Regards Les, Livingston, Scotland



Viewing all articles
Browse latest Browse all 48

Trending Articles



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