End SubPrivate Sub myWaveLine(obj As Object, x1 As Long, y1 As Long, x2 As Long, y2 As Long, intWidth As Integer, intsplit As Integer) Static intWave As Long Dim i As Long Dim j As Integer Dim xS As Long, yS As Long obj.DrawWidth = intWidth For i = 0 To intsplit - 1 xS = x1 + (x2 - x1) / intsplit * i yS = y1 + (y2 - y1) / intsplit * i
End Sub Private Sub Form_Load() Me.ScaleMode = 3 Me.Picture1.ScaleMode = 3 End SubPrivate Sub Timer1_Timer() Timer1.Enabled = False Call MyLines Timer1.Enabled = True End Sub
新建一个工程。窗体里面放一个按钮,一个picture box 一个timer,粘贴下面代码看看。
当然这个效果画出来 还是觉得动画效果有点分不出左右。而且动画之和X坐标有关,垂直的线段就只剩下闪烁了,算法还是可以调整,但是老婆催着要带儿子出门了,先贴出来吧。
Private Sub Command1_Click()
Timer1.Interval = 100
Timer1.Enabled = Not (Timer1.Enabled)
End SubPrivate Sub MyLines()
'直线例子
myWaveLine Picture1, 100, 30, 200, 30, 10, 10
'不同分段例子
myWaveLine Picture1, 100, 50, 200, 50, 10, 4
'方向例子
myWaveLine Picture1, 200, 70, 100, 70, 10, 4
'加粗例子
myWaveLine Picture1, 100, 100, 200, 100, 20, 5
'折线例子
myWaveLine Picture1, 100, 120, 180, 200, 20, 10
myWaveLine Picture1, 180, 200, 260, 120, 20, 10
End SubPrivate Sub myWaveLine(obj As Object, x1 As Long, y1 As Long, x2 As Long, y2 As Long, intWidth As Integer, intsplit As Integer)
Static intWave As Long
Dim i As Long
Dim j As Integer
Dim xS As Long, yS As Long obj.DrawWidth = intWidth
For i = 0 To intsplit - 1
xS = x1 + (x2 - x1) / intsplit * i
yS = y1 + (y2 - y1) / intsplit * i
For j = 0 To 9
obj.Line (xS + (x2 - x1) / 10 / intsplit * j, yS + (y2 - y1) / 10 / intsplit * j)-(xS + (x2 - x1) / 10 / intsplit * (j + 1), yS + (y2 - y1) / 10 / intsplit * (j + 1)), RGB(0, 0, 255 * Cos(((xS + (x2 - x1) / 100 * j + intWave) Mod intsplit) / intsplit * 3.14 / 2))
Next
Next
intWave = intWave + 1
End Sub
Private Sub Form_Load()
Me.ScaleMode = 3
Me.Picture1.ScaleMode = 3
End SubPrivate Sub Timer1_Timer()
Timer1.Enabled = False
Call MyLines
Timer1.Enabled = True
End Sub