2017-05-29 65 views
-1

我正在創建一個程序,用戶可以在這裏命令一隻烏龜在一個名爲面板1的白色面板上移動。我已經使用烏龜旋轉rotatefliptype 我現在正在在它後面跟上一條線。我有一些想法,包括將像素放置在符合要求的地方。我的一個問題是位置。是否有可能使地點相對於某個點? 我當前的代碼是:VB.NET試圖畫一條線

Sub imageCloner(clonedImage As Image, clonedWidth As Int16, clonedHeight As Int16, clonedLocation As Point) 
    'clone image 
    Dim dotImage As New PictureBox() 
    dotImage.Image = clonedImage 
    dotImage.Location = clonedLocation 
    dotImage.Width = clonedWidth 
    dotImage.Height = clonedHeight 
    dotImage.SizeMode = picBoxTurtle.SizeMode 
    panel1.Controls.Add(dotImage) 
End Sub 
Sub findGradient() 
    'gradient = rise/run 
    turtleMovementGradient = (turtleYLocation - turtleOriginalYLocation)/(turtleXLocation - turtleOriginalXLocation) 
End Sub 
Sub drawLine() 
    find the gradient 
    findGradient() 

    create variables 
    Dim xcounter As Int16 = 0 
    Dim ycounter As Int16 = 0 

    For ycounter = 1 To panel1.Height 
     For xcounter = 1 To panel1.Width 
      If ycounter/xcounter = turtleMovementGradient Then 
       imageCloner(blackDotOnePixel.Image, 1, 1, New Point(panel1.Width - xcounter, panel1.Height - ycounter)) 
      End If 
     Next 
    Next 
End Sub 

的的drawLine()子程序首先運行。 我需要幫助繪製線

回答

0

這應該給你一些想法。

Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint 
    ' Create a local version of the graphics object for the Panel. 
    Dim g As Graphics = e.Graphics 
    ' Draw a string on the Panel. 
    g.DrawString("This is a diagonal line drawn on the control", New Font("Arial", 10), Brushes.Red, New PointF(30.0F, 30.0F)) 
    ' Draw a line in the Panel. 
    g.DrawLine(System.Drawing.Pens.Red, Panel11.Left, Panel1.Top, Panel1.Right, Panel1.Bottom) 
End Sub 
+0

我有什麼要放在括號** **來運行這個子程序 –

+0

這是一個事件,所以它只要控制需要重新粉刷被調用,如果包括在你的計劃,你應該看到控件上的文本和行。 – Mike