Option Explicit Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Form_Load() Dim obj As Object For Each obj In Me.Controls If Me.Frame1.hwnd = GetParent(obj.hwnd) Then MsgBox obj.Name End If Next End Sub窗体一个 一个frame1 (我测试的,上面放2个textbox 1个command1)
Dim i As Long
For i = 1 To Controls.Count - 1 If Not TypeOf Controls(i) Is Frame Then MsgBox Controls(i).Name End If Next
用VB本身自带的功能就可以实现,不用声明API函数~~~~
yinweihong(真名:尹伟红) 的方法不错应该比下一个效率高
Dim objControl As Control For Each objControl In Me.Controls If objControl.Container.Name = "Frame1" Then objControl.Text = "12345" End If Next
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As LongPrivate Sub Form_Load()
Dim obj As Object
For Each obj In Me.Controls
If Me.Frame1.hwnd = GetParent(obj.hwnd) Then
MsgBox obj.Name
End If
Next
End Sub窗体一个 一个frame1 (我测试的,上面放2个textbox 1个command1)
For i = 1 To Controls.Count - 1
If Not TypeOf Controls(i) Is Frame Then
MsgBox Controls(i).Name
End If
Next
For Each objControl In Me.Controls
If objControl.Container.Name = "Frame1" Then
objControl.Text = "12345"
End If
Next
1.能用VB本身的函数实现方法的不要使用API.2.能用API实现的不要使用外部控件.