پرستو پارسایی
سه شنبه 19 اردیبهشت 1402, 10:22 صبح
Imports System.Drawing.Drawing2D
Imports System.IO
Imports System.Drawing
Public Class Form1
Private startPoint As Point
Private endPoint As Point
Private lineColor As Color = Color.Black ' Set the default color to black
Private arrowColor As Color = Color.Black ' Set the default color to black
Private arrowPoints As Point() ' The points of the last drawn arrow
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = MouseButtons.Left Then
startPoint = e.Location
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
If e.Button = MouseButtons.Left Then
endPoint = e.Location
Using g As Graphics = Graphics.FromHwnd(PictureBox1.Handle)
'Show the color dialog to select the line and arrow color
Using colorDialog As New ColorDialog()
colorDialog.Color = lineColor
If colorDialog.ShowDialog() = DialogResult.OK Then
lineColor = colorDialog.Color
arrowColor = colorDialog.Color
End If
End Using
g.DrawLine(New Pen(lineColor, 4), startPoint, endPoint)
'Calculate the angle of the line
Dim angle As Single = CSng(Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X) * 180 / Math.PI)
'Draw the arrowhead with the selected color
Dim arrowSize As Integer = 6
Dim arrowBrush As New SolidBrush(arrowColor)
Dim arrowPen As New Pen(arrowBrush, 4)
arrowPoints = {New Point(endPoint.X, endPoint.Y), New Point(endPoint.X - arrowSize, endPoint.Y - arrowSize), New Point(endPoint.X - arrowSize, endPoint.Y + arrowSize)}
Dim transform As New Matrix()
transform.RotateAt(angle, endPoint)
g.Transform = transform
g.FillPolygon(arrowBrush, arrowPoints)
g.DrawPolygon(arrowPen, arrowPoints)
g.ResetTransform()
End Using
End If
End Sub
End Class
Imports System.IO
Imports System.Drawing
Public Class Form1
Private startPoint As Point
Private endPoint As Point
Private lineColor As Color = Color.Black ' Set the default color to black
Private arrowColor As Color = Color.Black ' Set the default color to black
Private arrowPoints As Point() ' The points of the last drawn arrow
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
If e.Button = MouseButtons.Left Then
startPoint = e.Location
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
If e.Button = MouseButtons.Left Then
endPoint = e.Location
Using g As Graphics = Graphics.FromHwnd(PictureBox1.Handle)
'Show the color dialog to select the line and arrow color
Using colorDialog As New ColorDialog()
colorDialog.Color = lineColor
If colorDialog.ShowDialog() = DialogResult.OK Then
lineColor = colorDialog.Color
arrowColor = colorDialog.Color
End If
End Using
g.DrawLine(New Pen(lineColor, 4), startPoint, endPoint)
'Calculate the angle of the line
Dim angle As Single = CSng(Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X) * 180 / Math.PI)
'Draw the arrowhead with the selected color
Dim arrowSize As Integer = 6
Dim arrowBrush As New SolidBrush(arrowColor)
Dim arrowPen As New Pen(arrowBrush, 4)
arrowPoints = {New Point(endPoint.X, endPoint.Y), New Point(endPoint.X - arrowSize, endPoint.Y - arrowSize), New Point(endPoint.X - arrowSize, endPoint.Y + arrowSize)}
Dim transform As New Matrix()
transform.RotateAt(angle, endPoint)
g.Transform = transform
g.FillPolygon(arrowBrush, arrowPoints)
g.DrawPolygon(arrowPen, arrowPoints)
g.ResetTransform()
End Using
End If
End Sub
End Class