VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 取得控件绝对Top值
发表评论(0)作者:, 平台:, 阅读:10191, 日期:2000-04-06
取得控件绝对Top值

Public Function AbsoluteTop(ctlContl As Control) As Single

Dim wrkContl As Control

Dim wrkTopPos As Single


On Error GoTo AbsoluteTopError

'初始

Set wrkContl = ctlContl

wrkTopPos = 0

'循环

Do

If (wrkContl.Container.Name = ctlContl.Parent.Name) Then Exit Do

wrkTopPos = wrkTopPos + wrkContl.Top ' 计算位置

Set wrkContl = wrkContl.Container ' 下个控件

Loop


AbsoluteTop = wrkTopPos + ctlContl.Parent.Top

Exit Function


AbsoluteTopError:

AbsoluteTop = ctlContl.Top + ctlContl.Parent.Top

Exit Function

End Function