注册 登录
编程论坛 VB6论坛

求助! VB frame 嵌套 定位问题

hmj0745 发布于 2021-12-10 18:24, 1390 次点击
   如下图所示,像此种状态,Command1 的Left和Top 只是它相对于Frame2 左上角的值。 请问如何获取Command1相对于frm1的 Left 和Top 值
***************************************************************************************************************************
只有本站会员才能查看附件,请 登录



[此贴子已经被作者于2021-12-12 14:17编辑过]

3 回复
#2
hmj07452021-12-12 14:17
关于VB frame 嵌套定位有没有哪位朋友做过这方面的,可以提供一点思路吗,谢谢!
.paren 方法只能找到父窗体,找不到控件所在的上层 frame!!!! 卡住了!

只要用代码实现,识别出Command1这个控件的 上一级分组容器名称是 frame2就行了。

[此贴子已经被作者于2021-12-12 14:32编辑过]

#3
风吹过b2021-12-12 17:29
  Command1.Parent.Caption = "测试"                '所在窗体
  Command1.Container.Caption = "测试2"            '所在容器,直接在窗体上时,窗口为容器

-------测试代码--------
程序代码:
Dim x As Long, y As Long, obj As Object

x = Command1.Left                   '自己的坐标
y = Command1.Top
Set obj = Command1.Container        '上一层容器
Do
    If obj Is Me Then Exit Do       '如果为放控件的窗体本身退出循环
    x = x + obj.Left
    y = y + obj.Top
    Set obj = obj.Container         '继续取上一层容器
Loop
'If Me.MDIChild Then        '如果是mdi子窗体再加上窗口坐标
'
    x = x + Me.Top
'
    y = y + Me.Left
'
End If

Debug.Print x, y
Debug.Print Command1.Left, Command1.Top
Debug.Print Frame1.Left, Frame1.Top
Debug.Print Picture1.Left, Picture1.Top
#4
hmj07452021-12-12 18:23
完美,有了风版这一段精悍的代码,后续界面控件定位的问题全解决了!
对父级容器的理解,又学到了,感谢!
1