|
-
Apr 4th, 2002, 09:14 AM
#1
Thread Starter
Hyperactive Member
Selecting Square
Hi,
I have a form on wich I place some objects. These objects can get the focus. I want to create a selecting square that can select those objects. So a user should be able to draw a square on the form selecting the object within. How is this possible?
Thank you for your time and effort.
"Experience is something you don't get until just after you need it."
-
Apr 4th, 2002, 04:08 PM
#2
Thread Starter
Hyperactive Member
"Experience is something you don't get until just after you need it."
-
Apr 6th, 2002, 10:33 AM
#3
New Member
Why not use the On mouse down event and on mouse up events to establish a rectangle then check all objects in the space creates
so if the click at 10,10 and release on 20,20 then you have a rectangle now check all objects to see if they are in this area
Wahoo i know something or not as the case may be
-
Apr 7th, 2002, 02:43 PM
#4
Thread Starter
Hyperactive Member
Than you wont see the selecting square on the form right?
I though, maybe ther's a way to get such a thing in visual Basic, but I think this is not possible...

Thx anyway, maybe I'll use your methode instead.
"Experience is something you don't get until just after you need it."
-
Apr 7th, 2002, 03:25 PM
#5
Thread Starter
Hyperactive Member
This is how I've created a selecting square with your tip.
Create a form and place on it a shape. Make the shape transparant, set the borderstyle as dot and place the folowing code.
VB Code:
Dim shpX As Integer
Dim shpY As Integer
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
shpX = X
shpY = Y
shpSelect.Top = shpY
shpSelect.Left = shpX
shpSelect.Width = 100
shpSelect.Height = 100
shpSelect.Visible = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If shpX > 0 And shpY > 0 Then
If X - shpX > 0 Then
shpSelect.Width = X - shpX
Else
shpSelect.Width = shpX - X
shpSelect.Left = shpX - (shpX - X)
End If
If Y - shpY > 0 Then
shpSelect.Height = Y - shpY
Else
shpSelect.Height = shpY - Y
shpSelect.Top = shpY - (shpY - Y)
End If
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
shpX = 0
shpY = 0
shpSelect.Visible = False
End Sub
Remember, I've named by shape shpSelect and my form's scalemode is vbTwip.
The selecting is not yet done, but this should be inserted in the Mouse_up event.
Good luck...
Last edited by BShadow; Apr 7th, 2002 at 03:36 PM.
"Experience is something you don't get until just after you need it."
-
Apr 7th, 2002, 04:39 PM
#6
You should add a boolean variable that indicates whether the mouse is down at the moment. Only adjust the shape when the boolean is true. This way you save a little time on every mouse move.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 7th, 2002, 05:11 PM
#7
Thread Starter
Hyperactive Member
Well setting the shpX and shpY to zero is like a boolean right?
If they are zero, than don't do the shape thing...
If their not zero, than the Mouse_Down has set them to a value...
"Experience is something you don't get until just after you need it."
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
|