Results 1 to 6 of 6

Thread: Selection Box

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Beirut, Lebanon
    Posts
    318

    Selection Box

    How do I make a selection box disapear?

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    ...

    Code:
        NameOfControl.Visible = False
    ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Beirut, Lebanon
    Posts
    318
    Maybe I mis-explained, what the problem is.

    I'm trying to draw a selection box, here's how:

    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    fpx = x
    fpy = y
    isSelecting = true
    end sub

    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If isSelecting = True Then

    '??????????????? QUESTION LIES HERE ?????????????????
    ' I here have to erase the previous rectangle without
    ' removing any thing on the form.


    ' And Then,
    ' Draw a rectangle From (fpx, fpy) to (x,y)
    End If
    End Sub


    Thanks

  4. #4
    Zaei
    Guest
    Code:
    Form_mousedown(...)
       FIsavepicturetosomewhere...
       isselecting...
    end
    
    Form_mouseup(...)
      FISelect(...)
      FIBlitsavedpicture...
    end
    Hope you understand all of that.

    Z.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2001
    Location
    Beirut, Lebanon
    Posts
    318
    Hi there,

    Thank you for you help.

    But I don't think this will do the job. Because between the MouseDown, and the MouseUp events, there is the MouseMove, during which I'm drawing the new line, and Intend to remove the old one.

    Do you think I have to blt the image on each mouse move occurence?


    Thank you.

  6. #6
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    Here's how I did it in my map editor. NOTE: The key to it is that you use BitBlt to draw a rectangle that inverts the colors behind it wherever I say "Draw rectangle ..." (by using vbSrcNot I think).

    Code:
    Dim Selecting As Boolean
    Dim SelectX As Long, SelectY As Long
    Dim OldMouseX As Long, OldMouseY As Long
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
      Selecting = True
      SelectX = X
      SelectY = Y
      OldMouseX = X
      OldMouseY = Y
      'Draw a rectangle from [SelectX,SelectY] to [OldMouseX,OldMouseY] (the new selection)
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
      If Selecting Then
        'Draw a rectangle from [SelectX,SelectY] to [OldMouseX,OldMouseY]. This will erase the previous one, because inverting an inverted rectangle will restore it!
        OldMouseX = X
        OldMouseY = Y
        'Draw a rectangle from [SelectX,SelectY] to [OldMouseX,OldMouseY] (the new selection)
      End If
    End Sub
    
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
      Selecting = False
    End Sub
    There you have! Trust me, it works
    You have 2 ways of doing this: you can manually draw a rectangle, by drawing 4 lines around it; or draw a rectangle covering it all and then drawing another one inside it, 1 pixel smaller, like this:

    BitBlt from [SelectX, SelectY] to [OldMouseX, OldMouseY]
    BitBlt from [SelectX+1, SelectY+1] to [OldMouseX-1, OldMouseY-1]
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

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