draw coordinate Two dimensions graph of (x-y) visual basic

时间:2016-08-30 04:36:48

标签: vb.net


hey every one I want to make a program that able to draw coordinate graph of Two dimensions of (x-y).when I enter a value in (x) text box and (y) text box and hit draw button it well draw the graph in the blue picture box . I searched in web sit but I found only one method that draw using the mouse and this not what I want .This is the image of the program and and it supposed to draw in white line like this image

Private Sub PictureBox2_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox2.MouseMove
    Static last As Point
    If e.Button = Windows.Forms.MouseButtons.Left Then
        PictureBox2.CreateGraphics.DrawLine(Pens.White, last.X, last.Y, e.X, e.Y)
    End If
    last = e.Location
End Sub

this is the code that I found that draw using the mouse

2 个答案:

答案 0 :(得分:1)

您应该使用面板Graphic事件

中的Paint
Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)

    ' Create pen.
    Using blackPen As New Pen(Color.Black, 3)

        ' Create points that define line.
        Dim point1 As New Point(100, 100)
        Dim point2 As New Point(500, 100)

        ' Draw line to screen.
        e.Graphics.DrawLine(blackPen, point1, point2)

    End Using
End Sub

然后致电Panle1.Invalidate()以解除Paint事件

答案 1 :(得分:0)

最好有一些代码的详细信息,特别是如何以及在哪个类中存储X和Y坐标。顺便说一句,你在2点之间绘制一条线,这样你需要在表格上有两组X和Y坐标框。 之后,它就像使用DrawLine方法(https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawline(v=vs.110).aspx)在互联网上找到的一样简单,您只需要从“绘图”按钮的Click事件中触发它。

再次嗨,艾哈迈德 这是一个简单的表单示例,可以在单击按钮时绘制一条线。当然,它需要更多的自举以确保用户只输入像素数的整数值,并且在其基本形式中,(0,0)是面板的左上角,但它可以很容易地转换为左下角方法。 .. enter image description here

Class Form1

   Private Sub cmdDraw_Click(sender As Object, e As EventArgs) Handles cmdDraw.Click
      Dim x1 As Integer = Integer.Parse(txtX1.Text)
      Dim y1 As Integer = Integer.Parse(txtY1.Text)
      Dim x2 As Integer = Integer.Parse(txtX2.Text)
      Dim y2 As Integer = Integer.Parse(txtY2.Text)
      pnlMap.CreateGraphics.DrawLine(New Pen(Color.Black), x1, y1, x2, y2)
   End Sub

End Class