-
April 20th, 2012, 09:07 AM
#1
Controls positions
Hi all,
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.
For example,
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.
-
April 20th, 2012, 10:15 AM
#2
Re: Controls positions
You can achieve this by a small recursive function:
Code:
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
End Sub
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:
Code:
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.
-
April 20th, 2012, 10:27 AM
#3
Re: Controls positions
Yeah, thanks a lot, that is it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|