2013-04-23 89 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事件中。

相關問題