2013-04-23 83 views
0

我想绘制VB6中两个数组的线图,在vb6中绘制一个带有两个轴的线图

x(1 to 3) =1,2,3 
y(1 to 3) =1,2,3 

...轴的值为x = 1,2,3和y = 1,2,3。

我只知道这个命令:

picture1.line(x1,y1)-(x2,y2) 

...但这些没有任何轴选项标签等我正在与一个图形,但是没有轴 - 只是一个线相应选定点的斜率。

请给我代码名称轴,或任何其他更好的方式来生成在VB6图表。

回答

0

使用VB6,您可以利用可用于Form和PictureBox控件的自动缩放。

将PictureBox“Picture1”添加到您的表单中,并将两个Line控件LineX和LineY 放入到的PictureBox中。这些将形成轴。添加以下代码:

Option Explicit 

Private Sub DrawLines(x() As Single, y() As Single) 

    Dim nIndex As Long 

    ' Ensure x() and y() are the same size. 
    If UBound(x) <> UBound(y) Then 
     Err.Raise 1000, , "x() and y() are different sizes" 
    End If 

    ' First line: 
    If UBound(x) < 2 Then 
     Exit Sub 
    End If 

    ' Draw line between first two coordinates. 
    Picture1.Line (x(1), y(1))-(x(2), y(2)) 

    ' Subsequent lines: 
    For nIndex = 3 To UBound(x) 
     ' Draw line to next coordinate. 
     Picture1.Line -(x(nIndex), y(nIndex)) 
    Next nIndex 

End Sub 

Private Sub Form_Load() 

    SetupPictureBox Picture1 

End Sub 

Private Sub Picture1_Paint() 

    Dim x(1 To 4) As Single 
    Dim y(1 To 4) As Single 

    x(1) = 15! 
    y(1) = 15! 

    x(2) = 45! 
    y(2) = 45! 

    x(3) = 15! 
    y(3) = 45! 

    x(4) = 15! 
    y(4) = 15! 

    DrawLines x(), y() 

End Sub 

Private Sub SetupPictureBox(ByRef pct As PictureBox) 

    ' Set up coordinates for picture box. 
    pct.ScaleLeft = -100 
    pct.ScaleTop = -100 
    pct.ScaleWidth = 200 
    pct.ScaleHeight = 200 

    ' Set up coordinates for the X axis. 
    LineX.X1 = -100 
    LineX.X2 = 100 
    LineX.Y1 = 0 
    LineX.Y2 = 0 

    ' Set up coordinates for the Y axis. 
    LineY.X1 = 0 
    LineY.X2 = 0 
    LineY.Y1 = -100 
    LineY.Y2 = 100 

End Sub 

请注意,两个轴自动绘制自己。三角形的绘画代码包含在PictureBox的Paint事件中。

相关问题