Microsoft KB Archive/187740

= PRB: UserControl Resize Event Fails with MoveWindow API =

Article ID: 187740

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q187740



SYMPTOMS
The Resize Event of a UserControl will not fire if you use the MoveWindow API function to resize the window of the UserControl.

NOTE: Other API calls that manipulate the UserControl window, such as SetWindowPos, may also show this behavior.



CAUSE
When you manipulate the UserControl window through API calls, you bypass the UserControl Object. So any of the events that would normally get raised from a COM call to the UserControl may fail when you bypass the UserControl object and manipulate the UserControl's window directly.



RESOLUTION
Use the Visual Basic Move method.



STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION
When using the MoveWindow API function to move or resize a UserControl, the UserControl's Resize event will not fire. You will see the same behavior if the UserControl is in a standard EXE or a compiled OCX.

Steps to Reproduce Behavior
 Create a standard Exe Project. Form1 is created by default. Click Add UserControl from the Project menu to add a UserControl to the project. Change the BackColor of the UserControl to Red so you will be able to see the control.  Add the following code to the UserControl: Public Property Get hWnd As Long hWnd = UserControl.hWnd End Property

Private Sub UserControl_Resize Debug.Print "Resize!" End Sub  Add the UserControl to Form1.</li>  Add the following code to Form1: Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As _      Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, _       ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Private Sub Form_Load Me.ScaleMode = vbPixels End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, _      X As Single, Y As Single) Static Chop As Boolean

Chop = Not Chop With UserControl1 If Chop Then Call MoveWindow(.hWnd, X, Y, .Width \ 2, .Height \ 2, True) '.Move X, Y, .Width \ 2, .Height \ 2 'VB Move Method Else Call MoveWindow(.hWnd, X, Y, .Width * 2, .Height * 2, True) '.Move X, Y, .Width * 2, .Height * 2 'VB Move Method End If       End With End Sub </li> Save and run the project. Try clicking on the form and note that you will not see the Resize code in the UserControl run. If you comment out the call to the MoveWindow API function and use the Visual Basic Move method in place of the API call, you will see the Resize code for the UserControl run.</li></ol>

Additional query words: kbDSupport kbDSD kbVBp kbVBp500 kbCtrl kbVBp600

Keywords: kbprb KB187740

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.