台灣最大程式設計社群網站
線上人數
1090
 
會員總數:240889
討論主題:186656
歡迎您免費加入會員
討論區列表 >> VB6 >> 如何在picturebox中同時及時畫折線圖和正弦圖
[ 變換順序 ]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
如何在picturebox中同時及時畫折線圖和正弦圖
價值 : 100 QP  點閱數:329 回應數:0

樓主

olisun
門外漢
0 3
61 3
發送站內信

原來想利用二個timer,結果只能執行一個,如果只有利用一個來呼叫plot副程式,也無法同時出現二種圖
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

Dim sum_val, avg, st, std As Double
Dim pi As Double = 3.14159
Randomize()
numval = Format(10 * Rnd(), "#.000000")
sinval = Format(5 * Math.Sin(3 * pi / 20 * id) + 5, "#.000000")
TextBox1.Text = id & vbTab & numval & vbCrLf & TextBox1.Text
id = id + 1
Call plot() '呼叫plot副程式

sum_val = sum_val + numval
If id = 1 Then Exit Sub
avg = Format(sum_val / id, "#.000000")
st = st + (numval - avg) ^ 2
std = Format(Sqrt(st / (id - 1)), "#.000000")
Label1.Text = "avg:" & Space(5) & avg & vbCrLf & "std :" & Space(5) & std

End Sub

Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Dim sum_val, avg, st, std As Double
Dim pi As Double = 3.14159
Randomize()

sinval = Format(5 * Math.Sin(3 * pi / 20 * id) + 5, "#.000000")
id = id + 1
Call sinplot()

End Sub


Sub plot()
Dim psx, psy, sinpsx, sinpsy As Double
Dim px, py, sinpx, sinpy As Double
Dim k, j, m As Integer

gra = PictureBox1.CreateGraphics
gra.Clear(PictureBox1.BackColor)
psx = PictureBox1.Width / 20
psy = PictureBox1.Height / (a - b)

For m = 1 To 9 '畫9條線10格
gra.DrawLine(finepen, 0, CInt(m * 0.1 * PictureBox1.Height), PictureBox1.Width, CInt(m * 0.1 * PictureBox1.Height))
Next

py = ((a - b) - numval) * psy
If id <= 20 Then
'If id <= (c - b) Then
px = id * psx
pointarray(id).X = px
pointarray(id).Y = py
sinpointarray(id).X = px
sinpointarray(id).Y = py

For j = 1 To id
gra.DrawLine(drawpen, pointarray(j - 1).X, pointarray(j - 1).Y, pointarray(j).X, pointarray(j).Y)
gra.DrawLine(bluepen, sinpointarray(j - 1).X, sinpointarray(j - 1).Y, sinpointarray(j).X, sinpointarray(j).Y)
Next
End If
If id > 20 Then
For j = 1 To 20

' If id > (c - b) Then
'For j = 1 To (c - b)
pointarray(j - 1).Y = pointarray(j).Y
sinpointarray(j - 1).Y = sinpointarray(j).Y
Next
pointarray(20).Y = py
sinpointarray(20).Y = py
' pointarray((c - b)).Y = py
gra.DrawLines(drawpen, pointarray)
gra.DrawLines(bluepen, sinpointarray)
End If
gra.Dispose()


End Sub




搜尋相關Tags的文章: [ timer ] , [ picturebox ] ,
本篇文章發表於2016-12-26 22:50
別忘捐VP感謝幫助你的人 新手會員瞧一瞧
目前尚無任何回覆
[ 變換順序 ]   

回覆
如要回應,請先登入.