Line Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandezco
    New Member
    • Nov 2007
    • 9

    Line Help

    I am working a problem VB-2005 and I am a little confused. If I used the following, I can draw lines. But if I try to use what lesson calls for I cannot draw lines.
    graphicsObject. DrawLine(New Pen(Color.Black ), _
    e.X, e.Y, DIAMETER, DIAMETER)

    Versus

    graphicsObject. DrawLine(New Pen(Color.Black ), _
    x1, y1, x2, y2)
    is this because I used the following statement ealier in the program?

    ' set diameter of MouseDown line
    Private Const DIAMETER As Integer = 8
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    You haven't made it clear which one works, and which doesn't. Or what happens when it doesn't work.

    Comment

    • CyberSoftHari
      Recognized Expert Contributor
      • Sep 2007
      • 488

      #3
      You never point which event you are coding this and what is the value of x1,y1 and x2,y2!
      Is it x1,y1 and x2,y2 are constant or following the mouse pointer?

      Comment

      • sandezco
        New Member
        • Nov 2007
        • 9

        #4
        graphicsObject. DrawLine(New Pen(Color.Black ), _
        e.X, e.Y, DIAMETER, DIAMETER)

        This one works (and it is following the mouse) my eventual goal is going to be to calculate the distance between end points of this line.

        Comment

        • CyberSoftHari
          Recognized Expert Contributor
          • Sep 2007
          • 488

          #5
          First post what you did in your code and describe about your problem in detail. (Do not simply post 2 or 3 line of code.)

          Comment

          • sandezco
            New Member
            • Nov 2007
            • 9

            #6
            Originally posted by CyberSoftHari
            First post what you did in your code and describe about your problem in detail. (Do not simply post 2 or 3 line of code.)
            Here is what I have so far, most of it was based off of an example. I am suppose to use the following, but when I do I can not draw the line:

            [CODE=vbnet]graphicsObject. DrawLine(New Pen(Color.Black ), x1, y1, x2, y2)

            Public Class LineLengthForm

            Dim x1 As Integer
            Dim x2 As Integer
            Dim y1 As Integer
            Dim y2 As Integer

            ' specify whether moving the mouse should erase
            Private shouldErase As Boolean = False

            ' specify whether moving the mouse should draw
            Private shouldDraw As Boolean = False

            ' set diameter of MouseDown line
            Private Const DIAMETER As Integer = 8

            ' create and initialize Graphics object
            Private graphicsObject As Graphics = CreateGraphics( )

            ' handles LineLength's MouseDown event
            Private Sub LineLengthForm_ MouseDown(ByVal sender As Object, _
            ByVal e As System.Windows. Forms.MouseEven tArgs) _
            Handles Me.MouseDown

            ' draw on Form if the left button is held down
            If e.Button = Windows.Forms.M ouseButtons.Lef t Then
            shouldDraw = True
            ' erase black lines if right button is held down
            ElseIf e.Button = Windows.Forms.M ouseButtons.Rig ht Then
            shouldErase = True
            End If
            End Sub ' MouseDown

            ' handles LineLengthForm' s MouseMove event
            Private Sub LineLengthForm_ MouseMove(ByVal sender As Object, _
            ByVal e As System.Windows. Forms.MouseEven tArgs) _
            Handles Me.MouseMove

            ' draw line if mouse button is pressed
            If shouldDraw = True Then
            graphicsObject. DrawLine(New Pen(Color.Black ), _
            e.X, e.Y, DIAMETER, DIAMETER)
            ' mouse pointer "erases" if right mouse button is pressed
            ElseIf shouldErase = True Then
            graphicsObject. DrawLine(New Pen(BackColor), _
            e.X, e.Y, DIAMETER, DIAMETER)
            End If
            End Sub 'LineLength_Mou seMove

            ' handle LineLength's MouseUp event
            Private Sub LineLengthForm_ MouseUp(ByVal sender As Object, _
            ByVal e As System.Windows. Forms.MouseEven tArgs) _
            Handles Me.MouseUp

            shouldDraw = False ' do not draw on the form
            shouldErase = False ' do not erase
            End Sub 'LineLength_Mou seUp[/CODE]
            Last edited by Killer42; Nov 29 '07, 12:16 AM.

            Comment

            • CyberSoftHari
              Recognized Expert Contributor
              • Sep 2007
              • 488

              #7
              [CODE=vbnet]graphicsObject. DrawLine(New Pen(Color.Black ), _
              e.X, e.Y, DIAMETER, DIAMETER)[/CODE]
              here you have to change like
              [CODE=vbnet]
              graphicsObject. DrawLine(New Pen(Color.Black ), _
              X1, Y1, e.X, e.Y)[/CODE]

              and in mouse down event

              [CODE=vbnet]
              Private Sub LineLengthForm_ MouseDown(ByVal sender As Object, _
              ByVal e As System.Windows. Forms.MouseEven tArgs) _
              Handles Me.MouseDown

              ' draw on Form if the left button is held down
              If e.Button = Windows.Forms.M ouseButtons.Lef t Then
              shouldDraw = True
              ' erase black lines if right button is held down
              ElseIf e.Button = Windows.Forms.M ouseButtons.Rig ht Then
              shouldErase = True
              End If
              X1 = e.X
              Y1 = e.Y
              End Sub ' MouseDown[/CODE]

              and in mouse up X1 and Y1 to 0
              and same thing apply to errase logic.
              Note : This code will draw line to start and end point of mouse pointer. so it will not be a single line (it will look like shaded line, you don't draw a Straight line).
              Last edited by CyberSoftHari; Nov 29 '07, 04:50 AM. Reason: Note : This code

              Comment

              • sandezco
                New Member
                • Nov 2007
                • 9

                #8
                Thanks for the insight!!!!!!!! !!!

                Comment

                Working...