FIX: Cannot Disable UserControl on Modal Form (171972)
The information in this article applies to:
- Microsoft Visual Basic Control Creation Edition for Windows 5.0
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
This article was previously published under Q171972 SYMPTOMS
A UserControl created in Visual Basic and placed on a form that is opened
modally does not respond to attempts made to disable it. Setting the
Enabled property of the control behaves as expected on a non-modal form,
but setting Enabled = False on a modal form has no effect.
RESOLUTION
You can use the Windows API function EnableWindow to enable/disable the
ActiveX control. - In the General Declaration section of the module, place the following
declaration: (This must be declared as Private if it is included in a
form module.)
Private Declare Function EnableWindow Lib "user32" Alias _
"EnableWindow" (ByVal hwnd As Long, ByVal fEnable As Long) As Long
- The hWnd property, like all UserControl properties, requires a public
property method to expose the property as part of the object's
interface. Since you will not be setting a value, the Property Get
is all that is needed.
Public Property Get hWnd() as Long
hWnd=UserControl.hWnd
End Property
- Next, you need to associate this method with the hWnd property
of the control:
- From the Tools menu, select Procedure Attributes.
- Select "hWnd" from the Name drop-down list.
- Click the Advanced button.
- From the Procedure ID drop-down list, choose "hWnd." Click OK.
- The EnableWindow function can now be called to enable or disable the
UserControl. To disable the UserControl:
Dim result as Long
result = EnableWindow(Me.UserControl1.hWnd, 0)
To enable the UserControl:
Dim result as Long
result = EnableWindow(Me.UserControl1.hWnd, 1)
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article. This bug has been fixed in Visual Basic
6.0.
Modification Type: | Major | Last Reviewed: | 12/10/2003 |
---|
Keywords: | kbbug kbfix KB171972 |
---|
|