所以我使用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
当我运行并编译它时,每次我按住鼠标按钮,移动和释放时,我都可以画一条线。我可以选择这些行,我只是不知道如何添加代码,以便在我选择它时它会做一些事情。如果有人能帮助我,我将不胜感激。如果有人可以告诉我如何在单击一行及其起点和终点时显示消息框。
我正在创建一个结构分析程序,应该允许用户绘制建筑框架,然后单击线条并添加属性,例如它的材料等。
谢谢!!
京东
将点击处理程序添加到您的临时行...
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