PRB: UserControl Resize Event Fails with MoveWindow API
ID: Q187740
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
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.
- 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
- 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.
Additional query words:
kbDSupport kbDSD kbVBp kbVBp500 kbCtrl kbVBp600
Keywords : kbGrpVB
Version :
Platform : WINDOWS
Issue type : kbprb
|