Results 1 to 2 of 2

Thread: How Can I tell if a user Control is moved at design Time

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Is thre a way of telling if your usercontrol has been moved at design time. Something like the resize event but for moving the control rather than resizing it, or are there any other ways of doing it.

    I'm very wary about subclassing user controls at design time because that's almost a garrenteed way of freezing your machine. Does anyone know another method of doing this without having a timer keep checking it's position.

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    If you're talking about desing time only then you can do something like this. Put this code into the UserControl:

    Code:
    Private intLeft As Integer
    Private intTop As Integer
    
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End Type
    Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    
    
    Private Sub UserControl_ControlMove(ByVal pOldLeft As Integer, ByVal pOldTop As Integer, ByVal pNewLeft As Integer, ByVal pOldTop As Integer)
        'Do your things here to handle Control Move
    End Sub
    
    
    
    Private Sub Timer1_Timer()
        Dim rec As RECT
        
        Call GetWindowRect(UserControl.hwnd, rec)
        If intTop <> rec.Top Or intLeft <> rec.Left Then
            UserControl_ControlMove intLeft, intTop, rec.Left, rec.Top
            intTop = rec.Top
            intLeft = rec.Left
        End If
    End Sub
    
    Private Sub UserControl_Show()
        Dim rec As RECT
        
        Call GetWindowRect(UserControl.hwnd, rec)
        intTop = rec.Top
        intLeft = rec.Left
        Timer1.Interval = 50
    End Sub
    This way the procedure UserControl_ControlMove will fire if the control changed it's location.

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