|
-
Feb 20th, 2002, 09:38 AM
#1
Thread Starter
New Member
Moving 'shape' controls with mouse
Does anyone know any quick way of being able to move 'shape' (rectangle) controls around a picture box using a mouse.
As far as I know 'shape' controls don't allow DragNDrop mode.
Any help would be grateful, cheers.
-
Feb 20th, 2002, 11:17 AM
#2
Fanatic Member
Play around with MouseMove and MouseDown/MouseUp
Never argue with fools, they will only drag you down to their level, and beat you with experience.
Q: How do you tell an experienced hacker from a novice?
A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer
-
Feb 20th, 2002, 12:42 PM
#3
Frenzied Member
hm I think that's a pretty sucky thing to do because I think you are right that they do not have a drag and drop and I think they have no events either...
if not that's not going to be fun
you would need to check if a mouseclick is about the control and than move it with the mouse until you register a mouse up...
there could be some pretty funky things happening if you try to do this without api
Sanity is a full time job
Puh das war harter Stoff!
-
Feb 21st, 2002, 03:39 AM
#4
Thread Starter
New Member
No you're right the 'shape' control doesn't have any associated events, and it is going to be a bugger!
Aaaarrgggh, anybody got any reason why VB doesn't have an event for this control - it seems daft!
-
Feb 21st, 2002, 05:01 AM
#5
PowerPoster
It's not really a control, it's just there to 'pretty' up your app.
You could trap the events on the form the shapes are on and compare the co-ordinates of the mouse to the shapes position...?
Gentile or Jew,
O you who turn the wheel and look to windward,
Consider Phlebas, who was once handsome and tall as you...
-
Feb 21st, 2002, 07:28 AM
#6
Frenzied Member
that's what I meant and that also is a pain in the ... .
Especially if there is overlapping..
hm maybe you just want to use a picturebox and blit some kind of backbuffer with colors corresponding to each object, so you could use getpixel and look up which object that is...
Sanity is a full time job
Puh das war harter Stoff!
-
Feb 21st, 2002, 01:22 PM
#7
Thread Starter
New Member
A HAVE IT ALL UNDER CONTROL
The solution is below:
Must have the following controls on the form
PictureBox - PictureBox1 (Autoredraw=true, scalemode=pixels)
Shape - Shape1
Place shape1 anywhere inside the picturebox, and use:
Dim moveTriggered As Boolean
Dim shapeX As Integer
Dim shapeY As Integer
Dim shapeWidth As Integer
Dim shapeHeight As Integer
Dim xOffset As Integer
Dim yOffset As Integer
Private Sub Form_Load()
moveTriggered = False
shapeX = Shape1.Left
shapeY = Shape1.Top
shapeWidth = Shape1.Width
shapeHeight = Shape1.Height
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Select Case moveTriggered
Case True
If Button <> 1 Then
shapeX = Shape1.Left
shapeY = Shape1.Top
moveTriggered = False
Else
Shape1.Move (X - xOffset) + shapeX, Y - (yOffset - shapeY)
End If
Case False
If Button = 1 And X > shapeX And Y > shapeY Then
If X < shapeX + shapeWidth And Y < shapeY + shapeHeight Then
xOffset = X
yOffset = Y
moveTriggered = True
End If
End If
End Select
End Sub
It works a beauty. And you can release it, and keep moving it too, just what I wanted. Let me know if it works.
Cheers guys!
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
|