Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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..............
VB
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())

        'perpendicular line
      

    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
Posted
Updated 31-Jul-13 0:36am
v6
Comments
Post the code which you have tried and mark where exactly is the problem.
Nelek 31-Jul-13 6:23am    
Please use the "Improve question" widget to add needed information, what you have explained in the first version doesn't explain us enough to help you.
Are you having problems with the programming code or with the maths needed to find out angles and so on?
MinhajAli 31-Jul-13 6:35am    
@Nelek
actualy i am not able to find math angles, means x and y point. for creating perpendicular line.
in this application we have x1,y1,x2,y2 points,
if you show how to find x3,y3,x4,y4 value then i can solve my problem.

This is part of the code I used to draw a Eccentric reducer for a pipefitting program
This parts was in the print preview section of my program along with allot of other code.
This was the reference.
http://msdn.microsoft.com/en-us/library/aa983677(v=VS.71).aspx[^]
It uses GDI+
Notice the Values.

It produces two angle lines and two verticle lines to produce the shape.

VB
Dim p0 As System.Drawing.Point
Dim p1 As System.Drawing.Point
Dim p2 As System.Drawing.Point
Dim p3 As System.Drawing.Point


p0.X = 500
p0.Y = 200
p1.X = 500
p1.Y = 100
p2.X = 720
p2.Y = 44
p3.X = 720
p3.Y = 250

e.Graphics.DrawLine(myPen, p0, p1)
e.Graphics.DrawLine(myPen, p1, p2)
e.Graphics.DrawLine(myPen, p2, p3)
e.Graphics.DrawLine(myPen, p3, p0)
 
Share this answer
 
If you're just stuck on the math side of it...try google[^] for help.

This google result[^] actually posts graphs/pictures which is nice.

Hope this helps.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900