X Y Position in VB

We have a form and want the form to be display in specific x y based on the original calling form.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rayluvsAuthor Commented:
Sorry about.  It is in VBA.  We have a form created in VBA and want to display the form in top of a specific Text Box.  We were wondering if some sort of X/Y positioning where we can find the X/Y values of the master form then calculate it to the Text Box.
Here is a sample .
rayluvsAuthor Commented:
Let me provide an example, visually of what we are trying to accomplish.

The image provided is a 2 part image.  The first part display both Forms seperated but how we want it to be.  The second part display the Form2 where we want, under the Text Box.

The problem facing is if the user moves the window, we can't seem to coordinate the new x/y values.

Please keep in mind the this isn in VBA, no VB

Can this be possible?

Thanx !!

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

The following sample calculates the new x/y values, if the user moves the window.
In the following sample
Form2 is automatically placed under the text field
by a 300ms timer.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rayluvsAuthor Commented:
Worked excellently !

Can you give us a bit of explanation of how does it work so we can understand it:

Private Sub Command1_Click()

TextboxHeight = Form1.Text1.Height
Form1BlueCaptionFieldHeight = 20 * 15

Form2.Top = Form1.Top + Form1BlueCaptionFieldHeight + Form1.Text1.Top + TextboxHeight
Form2.Left = Form1.Left + Form1.Text1.Left

End Sub

Open in new window

rayluvsAuthor Commented:
We just stared to work with your recommendation, but noticed that thers really 3 forms: Form1 is the background form, Form2 would be the Customer form and Form3 would be the combo box.

With this in mind, what changes should we make to your calculations?
Form2.Show                                                    'makes the window visible
SetWindowPos Form2.hwnd, -1, 0, 0, 0, 0, 3 'shows Form2 permanently in foreground

TextboxHeight = Form1.Text1.Height
Form1BlueCaptionFieldHeight = 20 * 15 ' 15 Twips per pixel

Form2.Top = Form1.Top + Form1BlueCaptionFieldHeight + Form1.Text1.Top + TextboxHeight
Form2.Left = Form1.Left + Form1.Text1.Left
window positions
rayluvsAuthor Commented:
Thank you.

What about our doubt in ID: 37804064, when in 3 forms (see pic).  The thing is when started working with the solution, the reality is that its 3 forms.  As shown in the pic, its the same issue but with the background as form1, form2 as the Customer form and the last form3 as the form that we want to make it keep location as in the first example.

rayluvsAuthor Commented:
Note form2, at the moment and will cannot be move out of form1; always moving within form1.
I converted Form1 to a MDIform and I set the "MDIchild"
property  of Form2 to "True". So Form2 cannot be moved out of Form1.

The sample now has 3 Forms:
1) MDIForm (Form1)
2) Form2
3) Form3
WinXP sample6.zip
rayluvsAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.