Solved

X Y Position in VB

Posted on 2012-04-03
12
410 Views
Last Modified: 2012-04-06
We have a form and want the form to be display in specific x y based on the original calling form.
0
Comment
Question by:rayluvs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 

Author Comment

by:rayluvs
ID: 37803778
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.
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37803854
Here is a sample .
1.zip
0
 

Author Comment

by:rayluvs
ID: 37803899
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 !!

Image:
ee1
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:vb_elmar
ID: 37803937
The following sample calculates the new x/y values, if the user moves the window.
2.zip
0
 
LVL 17

Accepted Solution

by:
vb_elmar earned 500 total points
ID: 37803968
In the following sample
Form2 is automatically placed under the text field
by a 300ms timer.
3.zip
0
 

Author Comment

by:rayluvs
ID: 37803985
Worked excellently !

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

Private Sub Command1_Click()
Form2.Show

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

0
 

Author Comment

by:rayluvs
ID: 37804064
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?
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37804074
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
0
 

Author Comment

by:rayluvs
ID: 37804345
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.

ee2
0
 

Author Comment

by:rayluvs
ID: 37804347
Note form2, at the moment and will cannot be move out of form1; always moving within form1.
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 37804920
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
0
 

Author Comment

by:rayluvs
ID: 37817266
Thanx
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question