Results 1 to 2 of 2

Thread: Run Time moveable User Control not updating position properties.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Location
    St. Louis MO
    Posts
    129

    Question Run Time moveable User Control not updating position properties.

    I have a user control that I have made moveable at runtime with the following code:

    Option Explicit
    Private Const WM_NCLBUTTONDOWN As Long = &HA1&
    Private Const HTCAPTION As Long = 2&

    Private Declare Function ReleaseCapture Lib "user32" () As Long
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd&, ByVal wMsg&, wParam As Any, lParam As Any) As Long

    Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Not m_Movable Then
    Exit Sub
    End If

    Call ReleaseCapture
    Call SendMessage(UserControl.hWnd, WM_NCLBUTTONDOWN, ByVal HTCAPTION, ByVal 0&
    End Sub

    I add the control into the form at runtime with this - this code is ran from the form:
    Private Sub Add_Component(strComponentName As String)
    Dim ctlName As Control

    Set ctlName = frmreceiving.Controls.Add("scalemod9." & strComponentName, strComponentName, frmreceiving)

    ctlName.Visible = True
    ctlName.Top = 0
    ctlName.Left = 0
    Set ctlName = Nothing

    End Sub

    After the control is added to the form, I can drag it around the screen with the mouse at run time, but the controls left and top properties don't update to reflect it's new postion.
    When I ask for the top/left position it always returns wherever it was initially created at.
    Has anybody seen anything like this before?

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Maybe this moving method is something you can use...

    VB Code:
    1. Option Explicit
    2.  
    3. Dim XX, YY As Integer
    4.  
    5. Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    6.     XX = X
    7.     YY = Y
    8. End Sub
    9.  
    10. Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    11.     If Button = vbLeftButton Then
    12.         UserControl.Extender.Left = UserControl.Extender.Left + X - XX
    13.         UserControl.Extender.Top = UserControl.Extender.Top + Y - YY
    14.     End If
    15. End Sub


    Has someone helped you? Then you can Rate their helpful post.

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