Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to load a form and have it show at a specific position

Status
Not open for further replies.

Hackster

Programmer
Mar 28, 2001
173
0
0
US
I'm trying to emulate a popup menu using a form. The form has no ControlBox, no text in its Caption, with a startup position of Manual. It has a text box on it, and a command button. I need to call it from a command button event on the main form, and have the called form show at the exact same position as the button on the main form (just like a popup menu.) How would I do that?
 
Before proceeding with an answer, could you say why a popup menu itself is not acceptable?
 
Because I need to place a text box on it, and I don't believe you can place a text box on a menu. If you can, please let me know how. Thanks.
 
You can achieve this by trapping the X and Y values of the mouse button. In the load event of form that you want to call pass these(X,Y) values and set for calling forms 'top' and 'left' properties.

i hope that will solve your problems.

thanks
regards
rkp
 
You can achieve this by trapping the X and Y values of the mouse button. In the load event of form that you want to call pass these(X,Y) values and set for calling forms 'top' and 'left' properties.

i hope that will solve your problems.

thanks
regards
rkp
 
The X and Y values will change as the mouse moves. I can capture the X and Y values of the mouse when it is over the button that will load the form, but how do I tell the form that is being loaded that I wanted it to show where my mouse is?
 
Declare two public variables in general section. lets say
Public v1 as double
public v2 as double

in mousedown even
v1=x
v2=y

in the load even of called form
me.top=parenform.v1
me.left=parenform.v2

try this .. i have just tried this and it is working..
regards
rkp
 
When I tried it, the called form wound up in the upper left hand corner of the screen. As a test for this, I have a new project, and a Form1 and Form2. Form2 is the form being called that I want to show at my mouse position, which will be over a command button on Form1. Here is the code I used:
On Form1
Option Explicit

Public XPos As Integer
Public YPos As Integer

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
XPos = X
YPos = Y
End Sub

Private Sub Command1_Click()
Form2.Show
End Sub

On Form2
Private Sub Form_Load()
Me.Top = Form1.XPos
Me.Left = Form1.YPos
End Sub
 
Hi Hackster

Try flip-flopping the x,y
the x axis runs left to right
the y axis runs top to bottom

Jon
 
You should not use mouse_down event because the x and y values start from zero at the top left corner of the control, to which you assign the event. You should add the form1 and command1 top and left properties.

Try this:

Private Sub Form2_load()
Me.Top=Form1.Top + Form1!Command1.Top + 300
Me.Left=Form1.Left + Form1!Command1.Left
End Sub

+300 is because the Command1.Top starts counting from under the title bar of the form1 and the form's top property returns the position of the top of the title bar, so you have to add the title bar height. 300 is ok, if the scale mode (of the form2) is set to twips. If you have the scale mode set to different value, change the number as appropriate.

Hope this helps
Mangro
 
MangroBongacello: Thank you sir. Your suggestion worked like a champ!!
 
Oops... that code will place the form right over the button. If you want to show the form next to the mouse pointer then use tohose XPos and YPos values.

Private Sub Form2_load()
Me.Top=Form1.Top + Form1!Command1.Top + 300 + YPos
Me.Left=Form1.Left + Form1!Command1.Left + XPos
End Sub

Mangro
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top