本文主要是介绍vb使用picturebox画曲线图,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
'添加个picture1和command1
Option Explicit
Dim lngCenter As Long
Dim lngMax As Long
Dim lngPad&
Dim PCurrent As POINT, PLast As POINT
Private Type POINTx As Longy As Long
End Type
Private Sub Form_Load()lngCenter = (Picture1.Top + Picture1.Height) / 2lngMax = Picture1.HeightPLast.x = 0PLast.y = lngCenterDim i&For i = 0 To Picture1.Width Step 100Picture1.Line (i, 0)-(i, Picture1.Height), &HFFC0C0NextFor i = 0 To Picture1.Height Step 100Picture1.Line (0, i)-(Picture1.Width, i), &HFFC0C0NextPicture1.DrawWidth = 1.5Picture1.Line (0, lngCenter)-(Picture1.Width, lngCenter), vbBluePicture1.DrawWidth = 1
End Sub
Private Sub Timer1_Timer()PCurrent.x = PCurrent.x + 50RandomizePCurrent.y = Rnd * lngMaxPicture1.Line (PCurrent.x, PCurrent.y)-(PLast.x, PLast.y), vbRedPLast.x = PCurrent.xPLast.y = PCurrent.y
End Sub
Private Sub Command1_Click()Timer1.Enabled = Not Timer1.Enabled
End Sub
效果图:
如果需要带有点规律性可以将获得y的坐标稍加处理下:
Private Function getRndY() As Integer
Dim lngTmp%
If intRnd = 0 Then
Randomize
intRnd = Rnd * 3 + 1
End If
Randomize
lngTmp = Rnd * lngCenter
If PLast.y > lngCenter Then
getRndY = lngCenter + lngTmp
Else
getRndY = lngTmp
End If
intCurRnd = intCurRnd + 1
If intCurRnd > intRnd Then
Randomize
intRnd = Rnd * 3 + 1
getRndY = Rnd * lngMax
intCurRnd = 0
End If
End Function
这篇关于vb使用picturebox画曲线图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!