Alright, I am trying to create a graph that changes every second and just shows a 3 second history. In my head it would make sense to tie it into the T variable (Time in seconds), so I have form1 outputting T to a text box on form2 and then everytime that textbox changes it graphs the new chart.
The reason I am doing the step ladder approach is because I wanted the numbers to appear under the points as they travel.
does this make any sense at all, or am I completely off base?
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form2
Dim chart1 As New Chart
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
开发者_运维技巧 Private Sub TextBox11_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox10.TextChanged
If Form1.T <= 2 Then
Label1.Visible = False
TextBox20.Text = TextBox21.Text
TextBox31.Text = TextBox32.Text
TextBox21.Text = TextBox22.Text
TextBox32.Text = TextBox33.Text
TextBox22.Text = Form1.TextBox10.Text
TextBox33.Text = Form1.TextBox4.Text
Dim s1() As Point = {New Point(Form1.T - 2, TextBox20.Text), New Point(Form1.T - 1, TextBox21.Text), New Point(Form1.T, TextBox22.Text)}
Dim s2() As Point = {New Point(Form1.T - 2, TextBox31.Text), New Point(Form1.T - 1, TextBox32.Text), New Point(Form1.T, TextBox33.Text)}
For x As Integer = Form1.T - 2 To Form1.T
chart1.Series(0).Points.Add(x, s1(x).Y)
Next
chart1.Series.Add("Series2")
chart1.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Line
chart1.Series(1).ChartType = DataVisualization.Charting.SeriesChartType.Line
For x As Integer = Form1.T - 2 To Form1.T
chart1.Series(1).Points.Add(x, s1(x).Y)
Next
chart1.Series(0).Label = "PSS"
chart1.Series(1).Label = "USS"
End If
End Sub
End Class
I would move the code from the TextChanged event in to a public sub that takes the T variable as a parameter on the same form. From your first form you can just call the public sub directly without having to worry about using a hidden text box and it's events.
Something along the lines of...
Public Class Form2
Public sub TimerChange(T as integer)
...
End Sub
End Class
Then in the main form
Dim frm as new Form2
frm.show
frm.TimerChange(T)
精彩评论