Sub ControlProcessor(MyControl As Control) If TypeOf MyControl Is CommandButton Then Debug.Print "You passed in a " & TypeName(MyControl) ElseIf TypeOf MyControl Is CheckBox Then Debug.Print "You passed in a " & TypeName(MyControl) ElseIf TypeOf MyControl Is TextBox Then Debug.Print "You passed in a " & TypeName(MyControl) End If End Sub
要想得到usercontrol的容器的句柄,如果容器没有这个属性,直接用属性得不到,需要用API. GetParent Declare Function GetParent Lib "user32" Alias "GetParent" (ByVal hwnd As Long) As Long Private parentHWnd As Long
Private Sub UserControl_Show() parentHWnd = GetParent UserControl.hwnd end sub
'忘了括号. Private Sub UserControl_Show() parentHWnd =GetParent (UserControl.hwnd) end sub
If TypeOf MyControl Is CommandButton Then
Debug.Print "You passed in a " & TypeName(MyControl)
ElseIf TypeOf MyControl Is CheckBox Then
Debug.Print "You passed in a " & TypeName(MyControl)
ElseIf TypeOf MyControl Is TextBox Then
Debug.Print "You passed in a " & TypeName(MyControl)
End If
End Sub
GetParent Declare Function GetParent Lib "user32" Alias "GetParent" (ByVal hwnd As Long) As Long Private parentHWnd As Long
Private Sub UserControl_Show()
parentHWnd = GetParent UserControl.hwnd
end sub
Private Sub UserControl_Show()
parentHWnd =GetParent (UserControl.hwnd)
end sub
lHwnd=UserControl.ContainerHWnd