求助:picturebox实时曲线整体左移时部分网格线也出现左移问题?
各位大侠:大家好!
首先感谢大家解决了我以前的问题,特别是xzlxzlxzl美女高手,她能及时地解决我的问题。
但小弟喜欢捣鼓,现在又发现以下问题:
1、实时曲线整体左移时为什么部分网格线也出现左移问题?
2、如何在里面画虚线网络线,又不影响曲线整体左移的效果?
PictureBox中曲线左平移.rar
(7.08 KB)
Dim DataFromCom As Integer '从串口读过来的实时值 Dim DataFromComLast As Integer '上次的串口值 Dim TimeCount As Integer Private Sub Form_Load() '*********************************** '后台仅做复制过去再复制过来的动作 picBack.Visible = False picBack.DrawStyle = 2 picBack.DrawWidth = 1 PicScale picBack '调整图像框的坐标系 PicXLine picBack picBack.DrawStyle = 0 picBack.DrawWidth = 2 '*********************************** '*********************************** picShow.DrawStyle = 2 picShow.DrawWidth = 1 '画图要在前台画 PicScale picShow '调整图像框的坐标系 PicXLine picShow picShow.DrawStyle = 0 picShow.DrawWidth = 2 '*********************************** End Sub Private Sub PicScale(picX As PictureBox) '调整图像框的坐标系 picX.Scale (0, picX.ScaleHeight)-(picX.ScaleWidth, -picX.ScaleHeight) End Sub Private Sub PicXLine(picX As PictureBox) Dim intStep As Integer For intStep = 0 To 10 picX.Line (0, intStep * 1000)-(picX.ScaleWidth, intStep * 1000), vbBlack picX.Line (0, -intStep * 1000)-(picX.ScaleWidth, -intStep * 1000), vbBlack '用黑线清除原来的线 Next picShow.DrawStyle = 2 picShow.DrawWidth = 1 For intStep = 0 To 10 picX.Line (0, intStep * 1000)-(picX.ScaleWidth, intStep * 1000), vbWhite picX.Line (0, -intStep * 1000)-(picX.ScaleWidth, -intStep * 1000), vbWhite Next picShow.DrawStyle = 0 picShow.DrawWidth = 2 End Sub Private Sub DrawRealLine(picX As PictureBox, TimeCountX As Integer, DataFromComX As Integer, DataFromComLastX As Integer) picX.Line ((TimeCountX - 1) * 60, DataFromComLastX)-(TimeCountX * 60, DataFromComX), vbGreen End Sub Private Sub Timer_Timer() DataFromComLast = DataFromCom Randomize DataFromCom = CInt(1000 * Rnd) TimeCount = TimeCount + 1 '对出边界的判断要提前,另15缇=1像素,这样不会出现除不尽的情况 '这主要是你调整了坐标系导致的实际图形复制只复制了上半幅,下半幅未复制到,而负数的图形是画到下半幅的。将图形拷贝起点坐标系修改如下,则无论正负均会左移 If ((TimeCount + 1) * 60 > picBack.Width) Then picBack.PaintPicture picShow.Image, -60, -picShow.Height / 2, picShow.Width, picShow.Height, 0, -picShow.Height / 2, picShow.Width, picShow.Height '从前台复制到后台 picShow.PaintPicture picBack.Image, 0, -picShow.Height / 2, picShow.Width, picShow.Height, 0, -picShow.Height / 2, picBack.Width, picBack.Height '从后台显示到前台是立即进行的 TimeCount = TimeCount - 1 End If DrawRealLine picShow, TimeCount, DataFromCom, DataFromComLast 'OK PicXLine picShow '重画栅格线 End Sub