PDA

Click to See Complete Forum and Search --> : Run Time moveable User Control not updating position properties.


Tony Martin
Dec 27th, 2003, 12:18 PM
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?

manavo11
Dec 27th, 2003, 04:42 PM
Maybe this moving method is something you can use...

Option Explicit

Dim XX, YY As Integer

Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
XX = X
YY = Y
End Sub

Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
UserControl.Extender.Left = UserControl.Extender.Left + X - XX
UserControl.Extender.Top = UserControl.Extender.Top + Y - YY
End If
End Sub