Visual Basic Power Pack - 选择行

时间:2014-02-16 20:51:48

标签: vb.net powerpacks

所以我使用Visual Basic Power Pack来做一些基本的简单图形。我有能力在我需要的地方绘制很多行,而且VB电源包允许我选择我绘制的实际行,但我不知道如何在实际选择这些行时实现代码。

这是我的代码:

Imports Microsoft.VisualBasic.PowerPacks

Public Class Form1

    Dim ptA, ptB As Point                     ' starting and ending point
    Dim down = False
    Dim lines As New List(Of LineShape)
    Dim temp As LineShape                     ' temporary line to be drawn
    Dim canvas As New ShapeContainer          'shape container 

    Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
        down = True
        canvas.Parent = Me
        temp = New LineShape
        temp.Parent = canvas
        ptA = New Point(e.X, e.Y)
        temp.StartPoint = ptA
        temp.EndPoint = ptA
    End Sub

    Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles MyBase.MouseUp
        down = False
        ptB = New Point(e.X, e.Y)
        lines.Add(temp)
        temp = Nothing
    End Sub

    Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove
        If down = True Then
            temp.X2 = e.X
            temp.Y2 = e.Y
        End If
    End Sub

End Class

当我运行并编译它时,每次我按住鼠标按钮,移动和释放,我都可以画一条线。我可以选择行,我只是不知道如何添加代码,这样当我选择它时,它会做一些事情。如果有人能帮助我,我会非常感激。如果有人可能只是告诉我如何在点击一条线的起点和终点时显示一个消息框。

我正在创建一个结构分析程序,应该允许用户绘制建筑物框架,然后点击线条并添加属性,例如它所构成的材料等。

非常感谢!!

JD

1 个答案:

答案 0 :(得分:0)

向临时线路添加点击处理程序...

Imports Microsoft.VisualBasic.PowerPacks

Public Class Form1

    Dim ptA, ptB As Point                     ' starting and ending point
    Dim down = False
    Dim lines As New List(Of LineShape)
    Dim temp As LineShape                     ' temporary line to be drawn
    Dim canvas As New ShapeContainer          'shape container 

    Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
        down = True
        canvas.Parent = Me
        temp = New LineShape
        temp.Parent = canvas
        ptA = New Point(e.X, e.Y)
        temp.StartPoint = ptA
        temp.EndPoint = ptA
    End Sub

    Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles MyBase.MouseUp
        down = False
        ptB = New Point(e.X, e.Y)

        AddHandler temp.Click, AddressOf LineClickHandler

        lines.Add(temp)
        temp = Nothing
    End Sub

    Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles MyBase.MouseMove
        If down = True Then
            temp.X2 = e.X
            temp.Y2 = e.Y
        End If
    End Sub

    Private Sub LineClickHandler(sender As Object, e As MouseEventArgs)
        Dim MyLine As LineShape = DirectCast(sender, LineShape)

        MsgBox("Start = " & MyLine.StartPoint.ToString & " End Point = " & MyLine.EndPoint.ToString)
    End Sub

End Class