none
请大家帮个忙~~ RRS feed

  • 问题

  • 这是一段画一条抛物线的代码,原理上没问题,但从来没有画对过,总是画出两条线,一条抛物线,一条直线
      Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
            Dim graph As Graphics = Me.CreateGraphics
            Dim mypen As Pen = New Pen(Color.Blue, 3)
            Dim points(10) As Point
            For i As Integer = 0 To 8
                points(i).X = i ^ 3
                points(i).Y = i * 10
            Next
            graph.DrawCurve(mypen, points)
            mypen.Dispose()
        End Sub

    而且代码是从书上抄下来的,不知哪里有错?
    2009年6月7日 4:02

答案

  • 你好这是因为你的那个数组初始化的时候最后几点没有初始化 结果均为0,0所以会绘制那条直线
     因为你用的是for i=0 to 8只初始化了9个点 其他的都默认为0,0了
    
    应该改为
    
    Dim graph As Graphics = Me.CreateGraphics
          Dim mypen As Pen = New Pen(Color.Blue, 3)
          Dim points(10) As Point
          For i As Integer = 0 To 10
             points(i).X = i ^ 3
             points(i).Y = i * 10
          Next
          graph.DrawCurve(mypen, points)
          mypen.Dispose()
    
    
    或者
    
    Dim graph As Graphics = Me.CreateGraphics
          Dim mypen As Pen = New Pen(Color.Blue, 3)
          Dim points(8) As Point
          For i As Integer = 0 To 8
             points(i).X = i ^ 3
             points(i).Y = i * 10
          Next
          graph.DrawCurve(mypen, points)
          mypen.Dispose()
    

    努力着就不会放弃!.net技术交流群 33083877http://hi.baidu.com/1987raymond
    2009年6月7日 4:20
    版主