求助,VB.net picturebox操作
我用picturebox控件进行画线操作。涉及到2个函数(自己定义)。'----****----****----****----****----****----****----****----'
''函数: DrawVI()
''功能:画曲线。
'----****----****----****----****----****----****----****----'
Public Sub DrawVI(ByVal index As Integer, ByVal TVP As PictureBox, ByVal Vol As Single, ByVal Cur As Single)
Dim BeginningV As Point
Dim EndingV As Point
Dim BeginningI As Point
Dim EndingI As Point
Dim Yaxis_V As Single
Dim Yaxis_I As Single
Dim i As Integer
Dim VTZB As Graphics = TVP.CreateGraphics()
XStep(index) = 0.21 * (50 / XUnit(index))
Xnew(index) = Xnew(index) + XStep(index)
Yaxis_V = 280 - Vol / (SetVol(index) * 1.4) * 280 '电压
Yaxis_I = 280 - Cur / (SetCur(index) * 1.4) * 280 '电流
BeginningV.X = Xnew(index)
BeginningV.Y = Yaxis_V
EndingV.X = Xold(index)
EndingV.Y = YVold(index)
VTZB.DrawLine(Pens.Blue, BeginningV, EndingV) '画电压曲线
BeginningI.X = Xnew(index)
BeginningI.Y = Yaxis_I
EndingI.X = Xold(index)
EndingI.Y = YIold(index)
VTZB.DrawLine(Pens.Red, BeginningI, EndingI) '画电流曲线
Xold(index) = Xnew(index)
YVold(index) = Yaxis_V
YIold(index) = Yaxis_I
If Xnew(index) > 280 Then
XUnit(index) = XUnit(index) * 1.25
Xnew(index) = 5
Xold(index) = 5
YVold(index) = 280
YIold(index) = 280
Test = True
Select Case index
Case 0
LineZB(0, TVP1, SetVol(0), SetCur(0)) '///////////////////重新坐标轴绘制部分/////////////////////
For i = 1 To SerialNum(0)
DrawVI(0, TVP1, VolSave(0, i), CurSave(0, i))’///////////////////重新曲线绘制部分/////////////////////
Next
Case 1
LineZB(1, TVP2, SetVol(1), SetCur(1))
For i = 1 To SerialNum(1)
DrawVI(1, TVP2, VolSave(1, i), CurSave(1, i))
Next
Case 2
LineZB(2, TVP3, SetVol(2), SetCur(2))
For i = 1 To SerialNum(2)
DrawVI(2, TVP3, VolSave(2, i), CurSave(2, i))
Next
End Select
End If
Me.Invalidate()
VTZB.Dispose()
End Sub
''画坐标轴
Public Sub LineZB(ByVal index As Integer, ByVal TVP As PictureBox, ByVal LineV As Single, ByVal LineI As Single)
Dim Beginning As Point
Dim Ending As Point
Dim i As Byte
Dim TimeZB, VolZB, CurZB As String
Dim MyFont As Font
MyFont = New System.Drawing.Font("宋体", 9)
TVP.Image = New Bitmap(TVP.Width, TVP.Height)
Dim VTZB As Graphics = Graphics.FromImage(TVP.Image)
'画外框
VTZB.DrawRectangle(Pens.Black, 5, 0, 280, 280)
'画横坐标
For i = 0 To 5
Beginning.X = 45 + i * 40
Beginning.Y = 0
Ending.X = 45 + i * 40
Ending.Y = 280
VTZB.DrawLine(Pens.DarkGray, Beginning, Ending)
Next i
'画纵坐标
For i = 0 To 5
Beginning.X = 5
Beginning.Y = 40 + i * 40
Ending.X = 285
Ending.Y = 40 + i * 40
VTZB.DrawLine(Pens.DarkGray, Beginning, Ending)
Next i
'画刻度
For i = 0 To 7
Beginning.X = i * 38
Beginning.Y = 280
TimeZB = CStr(Format(i * XUnit(index), "0"))
VTZB.DrawString(TimeZB, MyFont, System.Drawing.Brushes.Black, Beginning.X, Beginning.Y)
Next
For i = 0 To 6
Beginning.X = 5
Beginning.Y = 228 - i * 38
Ending.X = 265
Ending.Y = 228 - i * 38
VolZB = LineV * 1.4 / 7 * (i + 1)
CurZB = LineI * 1.4 / 7 * (i + 1)
VTZB.DrawString(VolZB, MyFont, System.Drawing.Brushes.Black, Beginning.X, Beginning.Y)
VTZB.DrawString(CurZB, MyFont, System.Drawing.Brushes.Black, Ending.X, Ending.Y)
Next
Me.Invalidate()
VTZB.Dispose()
End Sub
我调用DrawVI,当曲线画到头时,我重新绘制坐标轴,并将先前保存在数据缓冲区中的数据重新绘制曲线,然后再接着进行绘图(仍调用DrawVI).
但是在picturebox中,重新绘制曲线部分为空白,详细见附件图:
请问各位高手,空白部分是怎么回事,怎么样避免。我试了N种办法,都是行不通。
谢谢。
[ 本帖最后由 galaxing 于 2012-10-15 21:35 编辑 ]