how can I find if a control is on the Form or is created in a Frame or other container.
I need that to know x,y coordonates.
Command1 Button is puted directly on the Form
Command2 Button is puted in Frame1
for Command1 x= Command1.x (y=blablabla)
for Command2 x= Frame1.x + Command2.x (y=blablabla)
I want to create a Global Function in a bas Module which send to another function this two parameters (x and y)
Basicly I want to show the MsgBox near to control box which generates the message
thanks for any sugestion
Last edited by nexusm; April 20th, 2012 at 10:30 AM.
You can achieve this by a small recursive function:
Private Sub ControlPosition(Cntl As Control, ByRef XPos As Integer, ByRef YPos As Integer)
Dim par As Object
XPos = XPos + Cntl.Left
YPos = YPos + Cntl.Top
Set par = Cntl.Container
If Not TypeOf par Is Form Then ControlPosition par, XPos, YPos
Note that XPos and YPos are ByRef, so as the function (sub) can modify them. Therefore you have to set them to zero before calling the Sub.
After calling, XPos and YPos represent the position of a control on a form, even when nested in multiple frames.
To determine these coordinates of, say a TextBox named Text1 you go:
Dim x%, y%
x = 0
y = 0
ControlPosition Text1, x, y
After that x and y hold the position of the control ON THE FORM where it is.
If you want to put a messagebox in beneath that control, you have to take the position of the Form in account, too.