Drawing a real-time curve in VB is more difficult, generally to apply third-party controls or Windows API functions, but if you are not very high for real-time curve, as long as we can express the current general situation, we can directly Apply VB to our space to complete.
In principle, it is possible to draw a curve directly in Form. Many routines above the MSDN are drawing graphics directly in Form, form as a container that draws graphics, but generally uses many other controls in Form. Therefore, we choose Picturebox as a container that draws a curve.
Drawing of real-time curves generally done by means of Timer controls, using Timer controls, regularly send data to PictureBox1 in other instruments, while drawing of the curve is generally drawn, and the line method of PictureBox1 is drawn. Specific The implementation is as follows:
1. Select the form that you want to display, add the picture box Picture1, to set the size of the picture and move to the appropriate location according to actual needs, and draw the range of the outside of the image ---- Time coordinate system; then add Timer control And two CommandButton, the interface is basically set.
2. Create a coordinate system, draw the X-axis and Y axis of the coordinate system according to the size and height of Picture1:
Picture1 .ScaleMode = 1 'in the unit as a basic unit to establish VB axis and drawing a figure; Picture1.RefreshPicture1.CurrentX = Picture1.ScaleLeft 100Picture1.CurrentY = Picture1.ScaleTop Picture1.Print Picture1.ScaleHeight - 100Picture1.Line (Picture1 .ScaleLeft 100, Picture1.ScaleTop 100) - (Picture1.ScaleLeft 100, Picture1.ScaleHeight - 100) Picture1.CurrentX = Picture1.ScaleLeft 100Picture1.CurrentY = Picture1.ScaleHeight Picture1.Print "(0,0)" Picture1.Line (Picture1.ScaleLeft 100, Picture1.ScaleHeight - 100) - (Picture1.ScaleWidth - 100, Picture1.ScaleHeight - 100) Picture1.CurrentX = Picture1.ScaleWidthPicture1.CurrentY = Picture1.ScaleHeight Picture1.Print Picture1.ScaleWidth- 100Picture1.autoredRAW = true "When necessary, redraw with the image stored in memory
3. Draw a curve and save, we use the sinus curve as a sine source of the drawing curve, the specific application is data that can be collected by serial port or other instruments. First we draw a midline, then draw a curve in the TIMER control Time event :
Picture1.Line (Picture1.ScaleLeft, CInt (Picture1.ScaleHeight / 2)) - (Picture1.ScaleWidth, CInt (Picture1.ScaleHeight / 2)) 'drawing the line Private Sub Timer1_Timer () Dim y1 As Integery1 = CInt (Sin (( X - Picture1.Left) / 20/180 * pi) * Picture1.scaleHeight / 2) Y1 = CINT ((Picture1.ScaleHeight 1000) / 2) - Y1Picture1.Line (x, y) - (x 20, Y1 ) x = x 20y y1IF x> = Picture1.scaleWidth Then SavePicture Picture1.Image, "c: /sin.bmp" Save Drawings, you can name the image according to actual needs X = 0 y = Picture1.scaleHeight / 2 Picture1. CLS 'clear screen Heavy Picture End IFEND SUB can be seen from the above process, in fact, the drawing of the real-time curve required is still relatively simple, here I use the clear screen heavy picture, if you want to implement the image to the left Move, the image still reserves, can use the Windows Bitblt function, allowing images to move a pixel or how many TWIPs each time, the specific implementation can see << Application VB4.0 Realize the real-time curve and historical curve of industrial control> > (http://www.swm.com.cn/yingyong/RJ-98-YY4/98-Y4-YY6.HTM).
The above is just a simple description of the real-time curve drawing. In the specific application, more effort to make more workfriends, the display time (can be implemented in accordance with the Picture1.Print in the code above), but the basic principle is small.