|
-
May 21st, 2000, 08:15 PM
#1
how do i find out if my usercontrol is currently visible on screen? i don't mean the .Visible property, my usercontrol can be set to visible, but it could be covered by another form or control.
thanks in advance
-
May 21st, 2000, 11:30 PM
#2
Fanatic Member
This function should do the trick, it might take a few little changes if you intend to use it in any other module than a form
Code:
Option Explicit
Private Declare Function IntersectRect Lib "user32" (lpDestRect As RECT, lpSrc1Rect As RECT, lpSrc2Rect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Debug.Print IsControlOverlapped(Label1)
End Sub
Private Function IsControlOverlapped(ctl As Control) As Boolean
Dim r1 As RECT, r2 As RECT, rdest As RECT
Dim tstctl As Control, ret As Long
With r1
'get dimensions of control being checked in pixels
.Top = Me.ScaleY(ctl.Top, vbTwips, vbPixels)
.Left = Me.ScaleX(ctl.Left, vbTwips, vbPixels)
.Right = .Left + (Me.ScaleX(ctl.Width, vbTwips, vbPixels))
.Bottom = .Top + (Me.ScaleY(ctl.Height, vbTwips, vbPixels))
End With
For Each tstctl In Controls
If Not ctl.Name = tstctl.Name Then
With r2
' get dimensions of current control in loop
.Top = Me.ScaleY(tstctl.Top, vbTwips, vbPixels)
.Left = Me.ScaleX(tstctl.Left, vbTwips, vbPixels)
.Right = .Left + (Me.ScaleX(tstctl.Width, vbTwips, vbPixels))
.Bottom = .Top + (Me.ScaleY(tstctl.Height, vbTwips, vbPixels))
End With
ret = IntersectRect(rdest, r1, r2) ' check to see if rects intersect
If ret = 0 Then
IsControlOverlapped = False
Else
IsControlOverlapped = True
Exit For ' exit loop if a control is found to overlap
End If
End If
Next
End Function
{Insert random techno-babble here}
{Insert quote from some long gone mofo here}
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
|