资源描述:
《vb使用picturebox画曲线图》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、OptionExplicitDimlngCenterAsLongDimlngMaxAsLongDimlngPad&DimPCurrentAsPOINT,PLastAsPOINTPrivateTypePOINTxAsLongyAsLongEndTypePrivateSubForm_Load()lngCenter=(Picture1.Top+Picture1.Height)/2lngMax=Picture1.HeightPLast.x=0PLast.y=lngCenterDimi&Fori=0ToPicture1.WidthStep100Picture1.Line(i,0)-(i,Pic
2、ture1.Height),&HFFC0C0NextFori=0ToPicture1.HeightStep100Picture1.Line(0,i)-(Picture1.Width,i),&HFFC0C0NextPicture1.DrawWidth=1.5Picture1.Line(0,lngCenter)-(Picture1.Width,lngCenter),vbBluePicture1.DrawWidth=1EndSubPrivateSubTimer1_Timer()PCurrent.x=PCurrent.x+50RandomizePCurrent.y=Rnd*lngMaxPic
3、ture1.Line(PCurrent.x,PCurrent.y)-(PLast.x,PLast.y),vbRedPLast.x=PCurrent.xPLast.y=PCurrent.yEndSubPrivateSubCommand1_Click()Timer1.Enabled=NotTimer1.EnabledEndSubOptionExplicitDimlngCenterAsLongDimlngMaxAsLongDimlngPad&DimPCurrentAsPOINT,PLastAsPOINTPrivateTypePOINTxAsLongyAsLongEndTypePrivate
4、SubForm_Load()lngCenter=(Picture1.Top+Picture1.Height)/2lngMax=Picture1.HeightPLast.x=0PLast.y=lngCenterDimi&Fori=0ToPicture1.WidthStep100Picture1.Line(i,0)-(i,Picture1.Height),&HFFC0C0NextFori=0ToPicture1.HeightStep100Picture1.Line(0,i)-(Picture1.Width,i),&HFFC0C0NextPicture1.DrawWidth=1.5Pict
5、ure1.Line(0,lngCenter)-(Picture1.Width,lngCenter),vbBluePicture1.DrawWidth=1EndSubPrivateSubTimer1_Timer()PCurrent.x=PCurrent.x+50RandomizePCurrent.y=Rnd*lngMaxPicture1.Line(PCurrent.x,PCurrent.y)-(PLast.x,PLast.y),vbRedPLast.x=PCurrent.xPLast.y=PCurrent.yEndSubPrivateSubCommand1_Click()Timer1.
6、Enabled=NotTimer1.EnabledEndSub效果图:如果需要带有点规律性可以将获得y的坐标稍加处理下:PrivateFunctiongetRndY()AsIntegerDimlngTmp%IfintRnd=0ThenRandomizeintRnd=Rnd*3+1EndIfRandomizelngTmp=Rnd*lngCenterIfPLast.y>lngCenterThengetRndY=lngCenter+lngTmpElsegetRndY=lngTmpEndIfintCurRnd=intCurRnd+1IfintCurRnd>intRndThenRandomiz
7、eintRnd=Rnd*3+1getRndY=Rnd*lngMaxintCurRnd=0EndIf本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/sysdzw/archive/2009/10/22/4712697.aspx