【问题标题】:Visual Basic Power Pack - Select LineVisual Basic Power Pack - 选择行
【发布时间】:2014-02-16 20:51:48
【问题描述】:

所以我正在使用 Visual Basic Power Packs 来做一些基本的简单图形。我有能力在我需要的地方画很多线,而且 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

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

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

非常感谢!!

京东

【问题讨论】:

  • 顺便说一句,如果有人试图在 VS2013 中运行它,不要忘记在项目中添加 Microsoft.VisualBasic.PowerPacks 引用。

标签: vb.net powerpacks


【解决方案1】:

将点击处理程序添加到您的临时行...

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

【讨论】:

  • 非常感谢。其实我早就想通了。我创建了一个类,并在该类中实现了可以返回更多有用信息的处理程序方法。再次感谢。
猜你喜欢
  • 1970-01-01
  • 2011-06-22
  • 1970-01-01
  • 2016-03-23
  • 2012-11-19
  • 1970-01-01
  • 2018-11-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多