Results 1 to 6 of 6

Thread: if a frm goes over a frm

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    226

    if a frm goes over a frm

    how do i make it so that if lets says frm1 enters any part of frm2 then something use happen

  2. #2
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: if a frm goes over a frm

    I don't know of an event that will tell you when one of your forms moves, but you could place this inside a timer.

    VB Code:
    1. If frm1.Top < frm2.Top + frm2.Height Then
    2.         If frm1.Top + frm1.Height > frm2.Top Then
    3.             If frm1.Left < frm2.Left + frm2.Width Then
    4.                 If frm1.Left + frm1.Width > frm2.Left Then
    5.                     'Do Something
    6.                 End If
    7.             End If
    8.         End If
    9.     End If

  3. #3
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: if a frm goes over a frm

    No there is not a move event in VB, shame really.
    My Flickr Stream


    My Sites Blog Twitter Flickr

  4. #4

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: if a frm goes over a frm

    And once you've subclassed that message you can check if the windows overlap using the intersectrect API:

    VB Code:
    1. Private Type RECT
    2.     lLeft As Long
    3.     lTop As Long
    4.     lRight As Long
    5.     lBottom As Long
    6. End Type
    7.  
    8. Private Declare Function IntersectRect Lib "user32" ( _
    9.                          lpDestRect As RECT, _
    10.                          lpSrc1Rect As RECT, _
    11.                          lpSrc2Rect As RECT) As Long
    12.  
    13. Private Declare Function GetWindowRect Lib "user32" ( _
    14.                          ByVal hwnd As Long, _
    15.                          lpRect As RECT) As Long
    16.  
    17. Private Function bOverlap(ByVal hWnd1 As Long, ByVal hWnd2 As Long) As Boolean
    18.     Dim rect1 As RECT, rect2 As RECT, rectDest As RECT
    19.    
    20.     GetWindowRect hWnd1, rect1
    21.     GetWindowRect hWnd2, rect2
    22.     IntersectRect rectDest, rect1, rect2
    23.    
    24.     With rectDest
    25.         bOverlap = .lLeft = .lTop = .lBottom = .lRight = 0
    26.     End With
    27. End Function

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    226

    Re: if a frm goes over a frm

    well i have a code that i have use to work before but now it doesnt

    VB Code:
    1. if frm1.left <= 300 and frm1.left >=100 and frm1.top >= 300 and frm1.top <= 500 then
    2. 'instert code
    that aint it extacly but u get the point. i use this code in another form and repeat the code 2 times in one form but i change the cordents
    VB Code:
    1. if frm1.left <= 300 and frm1.left >=100 and frm1.top >= 300 and frm1.top <= 500 then
    2. 'instert code
    3. elseif frm1.left <= 4000 and frm1.left >=3500 and frm1.top >= 4500 and frm1.top <= 5000 then
    4. 'instert code
    but the 2nd one wont work y?

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