Private Sub Command1_Click()
MsgBox Str((Form1.Top + Command1.Top) / Screen.TwipsPerPixelY)
MsgBox Str((Form1.Left + Command1.Left) / Screen.TwipsPerPixelX)
End Sub
MsgBox Str((Form1.Top + Command1.Top) / Screen.TwipsPerPixelY)
MsgBox Str((Form1.Left + Command1.Left) / Screen.TwipsPerPixelX)
End Sub
2、
用API函数ClientToScreentype POINTAPI
x as long
y as long
end type dim ptCmd as POINTAPI
with ptCmd
.x=commandbutton.left
.y=commandbutton.top
end with ClientToScreen commandbutton.hwnd,ptCmd
msgbox cstr(ptcmd.x)
msgbox cstr(ptcmd.y)
阿木说的对,用ClienttoScreen,在DELPHI中不是也一样用这个函数的吗!
caption和FORM边框会根据FORM不同的类型,大小不定
除非你用
select case Me.BorderStyle
case 1
…
end select
加以区分,再将其值进行计算