|
-
Nov 27th, 1999, 02:12 AM
#1
Thread Starter
Hyperactive Member
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.
-
Nov 27th, 1999, 02:32 AM
#2
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.
-
Nov 27th, 1999, 06:29 AM
#3
Thread Starter
Hyperactive Member
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.
-
Nov 27th, 1999, 07:28 PM
#4
Hyperactive Member
Maybe you can use a usercontrol and drop the lines on that.
-
Nov 28th, 1999, 01:29 AM
#5
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
-
Dec 18th, 2002, 09:35 PM
#6
Junior Member
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......
-
Dec 18th, 2002, 10:33 PM
#7
Fanatic Member
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
-
Dec 18th, 2002, 10:50 PM
#8
Junior Member
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......
-
Dec 19th, 2002, 01:47 AM
#9
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!
-
Dec 19th, 2002, 03:48 AM
#10
Junior Member
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......
-
Dec 19th, 2002, 04:30 AM
#11
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!
-
Dec 19th, 2002, 05:04 AM
#12
Junior Member
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......
-
Dec 19th, 2002, 05:29 AM
#13
You got to have PictureBox "PicBox" and Line-Control "Line1" visible on that PicBox and
OldMouseX and OldMouseY declared in General section
VB Code:
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!
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!
-
Dec 19th, 2002, 05:48 AM
#14
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:
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
Visual Studio 6, Visual Studio.NET 2005, MASM
-
Dec 19th, 2002, 05:57 AM
#15
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!
-
Dec 20th, 2002, 02:10 AM
#16
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|