PDA

Click to See Complete Forum and Search --> : lines as objects


joey o.
Nov 27th, 1999, 01:12 AM
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.

MartinLiss
Nov 27th, 1999, 01:32 AM
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.

joey o.
Nov 27th, 1999, 05:29 AM
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. :)

Crazy D
Nov 27th, 1999, 06:28 PM
Maybe you can use a usercontrol and drop the lines on that.

MartinLiss
Nov 28th, 1999, 12:29 AM
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

cutieCasper
Dec 18th, 2002, 08:35 PM
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 :confused:
*************

jian2587
Dec 18th, 2002, 09:33 PM
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.

cutieCasper
Dec 18th, 2002, 09:50 PM
oic. :eek:

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


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

opus
Dec 19th, 2002, 12:47 AM
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.

cutieCasper
Dec 19th, 2002, 02:48 AM
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
***********

opus
Dec 19th, 2002, 03:30 AM
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.

cutieCasper
Dec 19th, 2002, 04:04 AM
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
************

opus
Dec 19th, 2002, 04:29 AM
You got to have PictureBox "PicBox" and Line-Control "Line1" visible on that PicBox and
OldMouseX and OldMouseY declared in General section

Private Sub PicBox_MouseDown(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
If Button = vbLeftButton Then
'Store Startingmouseposition
OldMouseX=x
OldMouseY=y
End If
End Sub
Private Sub PicBox_MouseMove(Index As Integer, Button As Integer, Shift As Integer, x As Single, y As Single)
'moves a line if mouse-left is pressed
If Button = vbLeftButton Then
Line1.X2 = Line1.X2+(x-OldMouseX)
Line1.Y2 = Line1.Y2+(y-OldMouseY)
Line1.X1 = Line1.X1+(x-OldMouseX)
Line1.Y1 = Line1.Y1+(y-OldMouseY)
End If
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!

chemicalNova
Dec 19th, 2002, 04:48 AM
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)



Dim XStart, YStart As Integer

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button <> 1 Then Exit Sub

XStart = x
YStart = y
Picture1.AutoRedraw = False
Picture1.Refresh
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button <> 1 Then Exit Sub
Picture1.Refresh
Picture1.Line (XStart, YStart)-(x, y)
End Sub

Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
If Button <> 1 Then Exit Sub
Picture1.Refresh
Picture1.AutoRedraw = True
Picture1.Line (XStart, YStart)-(x, y)
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

opus
Dec 19th, 2002, 04:57 AM
Hi, Phreak,
your code just draws a line from MouseDown to MousUp, he wanted to move an existing line!


BTW How is live downunder?

cutieCasper
Dec 20th, 2002, 01:10 AM
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
*************