Hallo
Ich hab mal was gebastelt. Sind 2 Varianten, weil ich nich genau verstanden habe, was du möchtest. Nimm dir einfach ne Form und pack ne PictureBox und nen Timer rauf. Wechseln kannst du mit einem Klick auf die PictureBox. Und Timer aktivieren nich vergessen ;)Private bmp1 As New Bitmap(500, 200)
Private G1 As Graphics
Private lastX As Integer = -1
Private lastY As Integer = 0
Dim r As New Random
Private G2 As Graphics
Private bmp2 As New Bitmap(500, 200)
Dim data As Integer()
Dim index As Integer
Dim drawmode As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
data = CType(Array.CreateInstance(GetType(Integer), 250), Integer())
G1 = Graphics.FromImage(bmp1)
G1.Clear(Color.White)
G1.TranslateTransform(0, bmp1.Height \ 2)
G1.ScaleTransform(2, -1)
G1.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
G2 = Graphics.FromImage(bmp2)
G2.Clear(Color.White)
G2.TranslateTransform(0, bmp2.Height \ 2)
G2.ScaleTransform(2, -1)
G2.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
PictureBox1.Image = bmp1
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Timer1.Tick
Dim x As Integer = (lastX + 1) Mod bmp1.Width \ 2
Dim y As Integer = CInt(r.Next(70, 90) * Math.Sin((Environment.TickCount + _
r.Next(100)) / 400))
G1.FillRectangle(Brushes.White, x, -bmp1.Height \ 2, 5, bmp1.Height)
If x > lastX Then
G1.DrawLine(Pens.Green, lastX, lastY, x, y)
Else
G1.DrawLine(Pens.Green, -1, lastY, x, y)
End If
lastX = x
lastY = y
G1.Flush()
G2.Clear(Color.White)
index = val(1)
data(index) = y
G2.DrawLine(Pens.Blue, -1, data(val(0)), 0, data(val(0)))
For i As Integer = 1 To data.Length - 1
G2.DrawLine(Pens.Blue, i - 1, data(val(i - 1)), i, data(val(i)))
Next
G2.Flush()
PictureBox1.Refresh()
End Sub
Private Function val(ByVal i As Integer) As Integer
Return (index + data.Length + i) Mod data.Length
End Function
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles PictureBox1.Click
If drawmode Then
PictureBox1.Image = bmp1
Else
PictureBox1.Image = bmp2
End If
drawmode = Not drawmode
End Sub Speichern kannst du natürlich die Bilder selber. Alternativ dazu das Array und den aktuellen Index bei der zweiten Variante. Das hängt aber zu sehr davon ab, in welcher Form du deine Daten bekommst und verwaltet. |