Results 1 to 16 of 16

Thread: lines as objects

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Post

    How do I create a line as an object on a form that can be selected and moved by the user during runtime? The line control doesn't support this and I can't find anything more about the line method other than it's size and color.
    Thanks in advance.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    I don't believe that you can have the user select it, but you can move it by changing its X1, X2, Y1 and Y2 properties.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Post

    Thanks for trying Martin but I can't give up. If the answer isn't readily available maybe someone could suggest a source that might teach me to build it?
    Thanks again.

  4. #4
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386

    Post

    Maybe you can use a usercontrol and drop the lines on that.

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Try this:

    Place a Picturebox on your form. Its width should be the width that you want your line to be, its Appearance should be flat, its BorderStyle should be 0, its DragMode should be 1, and its BackColor should be the same as the BackColor of your form. Draw a line within the picturebox. Reduce the height of the picturebox to 60, and change the Y1 and Y2 properties of the line to 30. (I assume the line is horizontal) Add this code to your form’s DragDrop event Source.Move (X - Source.Width / 2), (Y - Source.Height / 2)


    ------------------
    Marty

  6. #6
    Junior Member
    Join Date
    Nov 2002
    Posts
    25

    Question


    Will need to know how to move the line drawn by the user and is able to move symetrically.
    I am currently using user control to do it.


    cutieCasper
    *************

    Live Life 2 D FULLEST......

  7. #7
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    Lines aren't objects. As far as line is concerned, they're just
    nothing more than just pixels bitblt'ed to the form's hDc.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  8. #8
    Junior Member
    Join Date
    Nov 2002
    Posts
    25

    oic.

    Is there any method I can use so that I will be able to draw and move the line?
    Need to do that.


    cutieCasper
    ************

    Live Life 2 D FULLEST......

  9. #9
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Your problem is that there is no IsOver_Event associated with the line-control.
    How do you "sense" when the user wants to move the line, most probably when he is clicking on with the mouse on it. You can determine when and whee he clicks. Compare the Where with the position of the line, if it's on the line ,you have you're starting point.
    This way you can also do the line drawing without the line-control and use the line-method.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  10. #10
    Junior Member
    Join Date
    Nov 2002
    Posts
    25

    Smile


    thanks.
    managed to draw the line but is unable to move the line.
    Put a default line in the user control and draw the line using it.

    How can I drag and drop or move the line?
    What I mean is move the user control in symetric.
    Thanks




    cutieCasper
    ***********

    Live Life 2 D FULLEST......

  11. #11
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    I'd use the mousemove event to drag/drop

    in this event (if the line was selected by a mousedown on it and the mousebutton is still down) print the line according to the offset from the original position (where was mousedown to where is mouse now). Stop that when mousebutton is released.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  12. #12
    Junior Member
    Join Date
    Nov 2002
    Posts
    25


    Thanks..
    I understand it but kind enough to provide me with the codes to drag/drop the line?

    Need to know how to calculate the position of the old and new position. (offset of the new position)
    Thanks



    cutieCasper
    ************

    Live Life 2 D FULLEST......

  13. #13
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    You got to have PictureBox "PicBox" and Line-Control "Line1" visible on that PicBox and
    OldMouseX and OldMouseY declared in General section
    VB Code:
    1. Private Sub PicBox_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
    2.     If Button = vbLeftButton Then
    3.        'Store Startingmouseposition
    4.        OldMouseX=x
    5.        OldMouseY=y
    6.    End If
    7. End Sub
    8. Private Sub PicBox_MouseMove(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
    9. 'moves a line if mouse-left is pressed
    10.     If Button = vbLeftButton Then
    11.         Line1.X2 = Line1.X2+(x-OldMouseX)
    12.         Line1.Y2 = Line1.Y2+(y-OldMouseY)
    13.         Line1.X1 = Line1.X1+(x-OldMouseX)
    14.         Line1.Y1 = Line1.Y1+(y-OldMouseY)
    15.     End If
    16. End Sub
    This code will not check if the mouseclick is on the line!
    Note:I don't have VB on hand to test that!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  14. #14
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    I created an Animation Program. It wasn't the best, but it worked how i did it. It had a frame editor and i used the PictureBoxes Line method to draw each line. Heres some code (not form my program)

    VB Code:
    1. Dim XStart, YStart As Integer
    2.  
    3. Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    4. If Button <> 1 Then Exit Sub
    5.  
    6. XStart = x
    7. YStart = y
    8. Picture1.AutoRedraw = False
    9. Picture1.Refresh
    10. End Sub
    11.  
    12. Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    13. If Button <> 1 Then Exit Sub
    14. Picture1.Refresh
    15. Picture1.Line (XStart, YStart)-(x, y)
    16. End Sub
    17.  
    18. Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    19. If Button <> 1 Then Exit Sub
    20. Picture1.Refresh
    21. Picture1.AutoRedraw = True
    22. Picture1.Line (XStart, YStart)-(x, y)
    23. End Sub

    There is extra in there also. Like, saving the lines colors, width, x y start/end and a listview contorl storing an icon and each lines information


    Hope that helped

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  15. #15
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Hi, Phreak,
    your code just draws a line from MouseDown to MousUp, he wanted to move an existing line!


    BTW How is live downunder?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  16. #16
    Junior Member
    Join Date
    Nov 2002
    Posts
    25

    Thumbs up



    Hi Opus,
    Thanks for the codes. Tried it out and it works.
    The only problem is that the line movement is to drastic.
    Will try to work that out.

    Thanks for the codes again.


    Hi Phreak,
    Thanks for providing me with the codes but like what Opus mentioned, I would like to move the line.

    Thanks anyway.



    cutieCasper
    *************

    Live Life 2 D FULLEST......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width