VB实时曲线的放大
我需要实现实时曲线的放大,我采用的是LINE方法进行绘制,并且曲线有背景网格,我怎么能够根据拖动坐标轴的变化(已经实现使用鼠标拖动坐标轴)对曲线进行实时放大啊?提供思路,有大家不吝赐教,本人万分感激
Public VertSplits As Long
Public Max As Single
Public lj As Integer
Private valuearray() As Single '存放数据的数组
Private LineColor As Long
Private GridColor As Long
Private ShowGrid As Boolean
Private pBox As PictureBox
Private pBoxHeight As Long
Private pBoxWidth As Long
Private pBoxleft As Long
Private MovingGrid As Boolean
Private StartPosition As Long
Private EndPosition As Long
Private GridPosition As Long
Public Enum DrawLineType
TYPE_LINE = 0
End Enum
Public LineType As DrawLineType '划线的类型:线或点
Const const_tolerance = 0.0001 '误差
Public Function InitDrawLine(pB As PictureBox, LColor As Long, SGrid As Boolean, Optional GColor As Variant, Optional MoveGrid As Variant)
pB.ScaleMode = vbPixels
LineColor = LColor
ShowGrid = SGrid
pBoxHeight = pB.ScaleHeight
pBoxWidth = pB.ScaleWidth
pBoxleft = pB.ScaleLeft
If IsMissing(GColor) Then
GridColor = RGB(0, 130, 0) '默认值绿色
Else:
GridColor = GColor
End If
If IsMissing(MoveGrid) Then
MovingGrid = False '如果用户未定MoveGrid值则默认为关。
Else:
MovingGrid = MoveGrid
End If
Set pBox = pB
'分配数组
ReDim valuearray(pBoxWidth - 9)
StartPosition = pBoxWidth - 10
EndPosition = pBoxleft + 10
GridPosition = 0
End Function
Public Sub AddValue(value As Single)
Dim l As Integer
'检查InitDrawline是否被执行,失败则退出
If pBox Is Nothing Then
Exit Sub
End If
'将数组所有值移动一位。
If Max <= 0 Then Max = 1
'把新的值添加到数组的最后一个元素。
If EndPosition <= pBoxWidth - 10 Then '显示未满一屏自左向右画曲线
'Select Case Combo1.Text
'Case "电机电压"
valuearray(EndPosition) = Rnd * 100 'pBoxHeight - ((value / Max) * pBoxHeight)
valuearray(EndPosition + 1) = valuearray(EndPosition)
lj = lj + 1
EndPosition = EndPosition + 1
End Select
Else '显示满屏后自动左移
For l = 1 To pBoxWidth - 10
valuearray(l - 1) = valuearray(l)
Next
valuearray(l - 1) = Rnd * 100 'pBoxHeight - ((value / Max) * pBoxHeight)
End If
GridPosition = GridPosition - 1
End Sub
Public Sub RePaint()
Dim x As Single
Dim y As Single
Dim l As Long
If pBox Is Nothing Then
Exit Sub
End If
'首先清除图片,然后画网格(如果有的话),最后画线。
pBox.Cls
If (ShowGrid) Then
pBox.ForeColor = GridColor
If (MovingGrid) Then
For x = GridPosition To pBoxWidth - 1 Step ((pBoxWidth - 1) / (VertSplits + 1)) - const_tolerance
pBox.Line (x, 0)-(x, pBoxHeight)
Next
Else:
For x = 0 To pBoxWidth - 1 Step ((pBoxWidth - 1) / (VertSplits + 1)) - const_tolerance
pBox.Line (x, 0)-(x, pBoxHeight)
Next
End If
For y = 0 To pBoxHeight - 1 Step ((pBoxHeight - 1) / (HorzSplits + 1)) - const_tolerance
pBox.Line (0, y)-(pBoxWidth, y)
Next
'网格复位
If GridPosition <= -Int((pBoxWidth - 1 / (HorzSplits + 1))) Then
GridPosition = 0
End If
End If
If StartPosition <= pBoxWidth - 1 Then
pBox.ForeColor = LineColor
Select Case DiagramType
Case TYPE_LINE
For l = pBoxleft + 10 To EndPosition - 10 Step 1
pBox.Line (l, valuearray(l))-(l + 1, valuearray(l + 1))
Next
End Select
End If
end sub
Private Sub Timer1_Timer()
Dim value As Single
tancounter = test(i) + 2
i = i + 1
If i > 100 Then
i = 1
End If
j = j + 1
LDraw.AddValue value
LDraw.RePaint
End Sub
[解决办法]
http://topic.csdn.net/u/20091225/12/a2cec261-a04b-4981-a3ca-23c231204802.html
http://topic.csdn.net/u/20090807/10/c269070f-278c-40df-a708-c1881548fbbd.html
[解决办法]
以后要吸取教训了,回帖之前先看看结帖率.