我如何从一个点到另一个点绘制线条 [英] How do i Draw line from one point to another

查看:95
本文介绍了我如何从一个点到另一个点绘制线条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Sub Drawline(Routeindex As Integer, cityindex As Integer)
 NumRoutes = NumRoutes + 1

Load Route(Routeindex)
With Route(Routeindex)
        .X1 = DB(cityindex) + NumRoutes
        .Y1 = DB(cityindex)  + NumRoutes
        .X2 = DB - NumRoutes
        .Y2 = DB - NumRoutes
        .Visible = True

End With


End Sub

推荐答案

如果您使用的是vb.net,并且想要使用鼠标在图片框控件中绘制线条,那么



If you are using vb.net and you want to draw line in picturebox control using mouse then

Dim startpoint As Point
   Dim endpoint As Point
   Dim flag As Boolean = False
   Private Sub PictureBox1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
       startpoint = New Point(e.X, e.Y)
       flag = True

   End Sub


   Private Sub PictureBox1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
       If flag Then
           Dim g As Graphics = PictureBox1.CreateGraphics()
           endpoint = New Point(e.X, e.Y)
           g.Clear(Color.White)
           g.DrawLine(Pens.Black, startpoint, endpoint)
       End If
   End Sub

   Private Sub PictureBox1_MouseUp(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
       flag = False
   End Sub







如果你想在表格窗口上画线然后使用




If you want to draw line on form window then use

me

而不是

picturebox1

并使用表格事件而不是图片框鼠标事件。

and use form events instead of picturebox mouse events.


这篇关于我如何从一个点到另一个点绘制线条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆