Results 1 to 7 of 7

Thread: Selecting Square

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425

    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."

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425

    Unhappy

    Anybody?
    "Experience is something you don't get until just after you need it."

  3. #3
    New Member
    Join Date
    Mar 2002
    Posts
    15

    Lightbulb

    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

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425
    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."

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425
    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:
    1. Dim shpX As Integer
    2. Dim shpY As Integer
    3.  
    4. Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    5.     shpX = X
    6.     shpY = Y
    7.    
    8.     shpSelect.Top = shpY
    9.     shpSelect.Left = shpX
    10.     shpSelect.Width = 100
    11.     shpSelect.Height = 100
    12.     shpSelect.Visible = True
    13. End Sub
    14.  
    15. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    16.     If shpX > 0 And shpY > 0 Then
    17.         If X - shpX > 0 Then
    18.             shpSelect.Width = X - shpX
    19.         Else
    20.             shpSelect.Width = shpX - X
    21.             shpSelect.Left = shpX - (shpX - X)
    22.         End If
    23.         If Y - shpY > 0 Then
    24.             shpSelect.Height = Y - shpY
    25.         Else
    26.             shpSelect.Height = shpY - Y
    27.             shpSelect.Top = shpY - (shpY - Y)
    28.         End If
    29.     End If
    30. End Sub
    31.  
    32. Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    33.     shpX = 0
    34.     shpY = 0
    35.     shpSelect.Visible = False
    36. 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."

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425
    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
  •  



Click Here to Expand Forum to Full Width