建立一个工程: 建立一个窗口 Form1 再增加一个Picture1 再增加一个按扭 Command1 你再在Picture1中增加任意个控件. 将以下代码复制至窗口中 运行代码. 按Commmand1之后,看是不是你要的结果?Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpREct As RECT) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Dim lpREct As RECT Private Sub Command1_Click() MsgBox "Picture1中有" & inPicCount(Picture1, Form1) & "个控件." End SubPrivate Function inPicCount(ByVal Pic As PictureBox, ByVal frm As Form) As Long Pic.BorderStyle = 0 Pic.ScaleMode = 1 frm.ScaleMode = 1 frm.BorderStyle = 2 Add = 0 Dim oControl As Control For Each oControl In Me.Controls GetWindowRect oControl.hwnd, lpREct If lpREct.Left = (oControl.Left + Pic.Left + frm.Left) / Screen.TwipsPerPixelX + 4 Then Add = Add + 1 End If Next End Function
建立一个工程: 建立一个窗口 Form1 再增加一个Picture1 再增加一个按扭 Command1 你再在Picture1中增加任意个控件. 将以下代码复制至窗口中 运行代码. 按Commmand1之后,看是不是你要的结果? Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpREct As RECT) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Dim lpREct As RECT Private Sub Command1_Click() MsgBox "Picture1中有" & inPicCount(Picture1, Form1) & "个控件." End SubPrivate Function inPicCount(ByVal Pic As PictureBox, ByVal frm As Form) As Long Pic.BorderStyle = 0 Pic.ScaleMode = 1 frm.ScaleMode = 1 frm.BorderStyle = 2 Add = 0 Dim oControl As Control For Each oControl In Me.Controls GetWindowRect oControl.hwnd, lpREct If lpREct.Left = (oControl.Left + Pic.Left + frm.Left) / Screen.TwipsPerPixelX + 4 Then inPicCount = inPicCount+ 1 '这一句和上例比有改过 End If Next End Function 这样才是正确的.刚
Private Sub Command1_Click() Dim c As Control, i As Integer For Each c In Me.Controls If c.Container Is Picture1 Then Debug.Print c.Name i = i + 1 End If Next MsgBox "picture1里面一共有" + CStr(i) + "个控件" End Sub
建立一个窗口 Form1 再增加一个Picture1 再增加一个按扭 Command1
你再在Picture1中增加任意个控件.
将以下代码复制至窗口中
运行代码.
按Commmand1之后,看是不是你要的结果?Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpREct As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim lpREct As RECT
Private Sub Command1_Click()
MsgBox "Picture1中有" & inPicCount(Picture1, Form1) & "个控件."
End SubPrivate Function inPicCount(ByVal Pic As PictureBox, ByVal frm As Form) As Long
Pic.BorderStyle = 0
Pic.ScaleMode = 1
frm.ScaleMode = 1
frm.BorderStyle = 2
Add = 0
Dim oControl As Control
For Each oControl In Me.Controls
GetWindowRect oControl.hwnd, lpREct
If lpREct.Left = (oControl.Left + Pic.Left + frm.Left) / Screen.TwipsPerPixelX + 4 Then
Add = Add + 1
End If
Next
End Function
建立一个窗口 Form1 再增加一个Picture1 再增加一个按扭 Command1
你再在Picture1中增加任意个控件.
将以下代码复制至窗口中
运行代码.
按Commmand1之后,看是不是你要的结果?
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpREct As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim lpREct As RECT
Private Sub Command1_Click()
MsgBox "Picture1中有" & inPicCount(Picture1, Form1) & "个控件."
End SubPrivate Function inPicCount(ByVal Pic As PictureBox, ByVal frm As Form) As Long
Pic.BorderStyle = 0
Pic.ScaleMode = 1
frm.ScaleMode = 1
frm.BorderStyle = 2
Add = 0
Dim oControl As Control
For Each oControl In Me.Controls
GetWindowRect oControl.hwnd, lpREct
If lpREct.Left = (oControl.Left + Pic.Left + frm.Left) / Screen.TwipsPerPixelX + 4 Then
inPicCount = inPicCount+ 1 '这一句和上例比有改过
End If
Next
End Function
这样才是正确的.刚
Dim c As Control, i As Integer
For Each c In Me.Controls
If c.Container Is Picture1 Then
Debug.Print c.Name
i = i + 1
End If
Next
MsgBox "picture1里面一共有" + CStr(i) + "个控件"
End Sub
我知道Parent
但是调试中发现都是 Form1 所以用那笨办法.
现在也知道原来还有一个Container.