Hi
I am developing an application in vb.net and want to draw perpendicular line against a parallel line
Like but not able to do if anyone know how to do please help
Thanks in Advance
like
http://tinypic.com/r/6h5nqt/5[
^]
but not able to do if anyone know how to do please help
Thanks in Advance
I am using the code to for creating the line is..............
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
picRegion.Image = Image.FromFile("C:/ss.jpg")
End Sub
Private m_BufferGraphics As Graphics
Private m_Drawing As Boolean
Private m_BufferBitmap As Bitmap
Private m_X1 As Integer
Private m_Y1 As Integer
Private m_X2 As Integer
Private m_Y2 As Integer
Private m_X3 As Integer
Private m_Y3 As Integer
Private m_X4 As Integer
Private m_Y4 As Integer
Private Sub PictureBox1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picRegion.MouseDown
If e.Button <> MouseButtons.Left Then Exit Sub
m_Drawing = True
SaveSnapshot()
m_X1 = e.X
m_Y1 = e.Y
End Sub
Private Sub SaveSnapshot()
Dim new_bitmap As Bitmap
new_bitmap = New Bitmap(Me.picRegion.Image.Size.Width, Me.picRegion.Image.Size.Height, Me.picRegion.CreateGraphics())
m_BufferGraphics = Graphics.FromImage(picRegion.Image)
m_BufferBitmap = new_bitmap
End Sub
Private Sub PrivewForm(ByVal gr As Graphics)
If Not (m_BufferBitmap Is Nothing) Then gr.DrawImage(m_BufferBitmap, 0, 0)
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picRegion.MouseMove
If Not m_Drawing Then Exit Sub
m_X2 = e.X
m_Y2 = e.Y
PrivewForm(Me.picRegion.CreateGraphics())
Me.picRegion.Refresh()
Dim pen As New Pen(Color.Crimson, 3)
Me.picRegion.CreateGraphics().DrawLine(pen, m_X1, m_Y1, m_X2, m_Y2)
PrivewForm(Me.picRegion.CreateGraphics())
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picRegion.MouseUp
If Not m_Drawing Then Exit Sub
m_Drawing = False
m_X2 = e.X
m_Y2 = e.Y
Dim pen2 As New Pen(Color.Crimson, 3)
m_BufferGraphics.DrawLine(pen2, m_X1, m_Y1, e.X, e.Y)
Me.picRegion.Refresh()
If m_Y1 = m_Y2 Then
m_X3 = m_X1
m_Y3 = m_Y1 - 15
m_X4 = m_X1
m_Y4 = m_Y1 + 15
Dim pen31 As New Pen(Color.Cyan, 3)
m_BufferGraphics.DrawLine(pen31, m_X3, m_Y3, m_X4, m_Y4)
Me.picRegion.Refresh()
m_X3 = m_X2
m_Y3 = m_Y2 - 15
m_X4 = m_X2
m_Y4 = m_Y2 + 15
Dim pen32 As New Pen(Color.Cyan, 3)
m_BufferGraphics.DrawLine(pen32, m_X3, m_Y3, m_X4, m_Y4)
Me.picRegion.Refresh()
End If
End Sub
End Class
in mouse up event where i have usage If m_Y1 = m_Y2 , this condition is only when a line is horizontal but if line is not horizontal perpendicular line is not generating.
sorry for bad English