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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Position A Form Relative To Mouse

Status
Not open for further replies.

CDavis

Programmer
May 5, 2000
155
US
The keyword search facility is down so I hope this isn't redundant.

For this question, I'm using VFP 3.0

I've created a date picker calendar that is a modal form called by the click event of text boxes on other forms. The text boxes are date types. The user can pick a date from the calendar which is returned as a value to the text box. That part is working well.

I've set the calendar form to auto center but what I'd really like is for the calendar to open on the screen relative to where the mouse was positioned during the click event of the text box.

Any suggestions?

Thanks for your help in advance.

Chuck Davis
 
Chuck

The .MouseDown event of a control has parameters, two of which are nXCoord, nYCoord.

You can use those values to determine the top and left position of your calendar form by passing the values as parameters to the .Init event of your Calendar form.

If you need further help, please advise.

Chris :)
 
Thanks Chris, I had already played with coordinates some and wasn't getting results -- Typical at the end of the day.

I put the following code in the click event of the text box. You'll notice that I built my own coordinates using the top and left properties of the parent object. I also considered the height of the text box and put in some fudge factors to adjust for the height of the parent's title bar and borders. -- I suppose other things that may need to be considered is whether the parent form has a half height or full size title bar. Other considerations would be to ensure that the calendar doesn't open below the bottom of the screen.

nXCoord = This.Parent.Left + This.Left + 2
nYCoord = This.Parent.Top + This.Top + This.Height + 25
DO FORM Calendar.scx WITH (This.Value),nXCoord,nYCoord
This.Value = mydate
RELEASE mydate

Any further comments by the forum will be appreciated as well.

Chuck Davis
 
Chuck, unbelievably I was doing the exact same thing with my app. Your code helped some, but I now have a problem with the form itself.

If I set the ShowWindow to be 1- In Top Level form, it works okay, but it defeats the purpose (the purpose being that if a date control is at the bottom of the form, I want the calendar form to come up below it regardless of whather the main form ends or not [kinda like overlapping forms])

If I set it to 0- As Top Level form, then when I call the calendar form, the calling form is hidden, which just looks silly.

How are you doing it, or does anyone else have some points of interest? My calendar form is Modal, so that I can return values to the calling form.
 
I haven't run into that problem -- but then I generally haven't used formsets but individual forms so finding the form coordinates is not as convoluted. I would have to do some testing to reproduce your circumstances -- I would think that stepping back through each object to it's container until you get back to the point where you are actually reading coordinates that relate to the screen should take care of the problem.

If you post your e-mail I'd be happy to send you my calendar and the test form I've been working with -- that might give you something additional to work with. I'd be interested to know how your calendar design differs from mine. Mine was quick and dirty about 4 hours of coding. But you are welcome to it.

Chuck Davis
 
Hi
Send the text box object as parameter to your calender.
Once you have access to this Object in your calendar class you can do something like this...
Code:
*// tMyObject is the object you called your calender from.
*// the text box in your case. You have to send it as 
*// parameter to the modal form (your calender form)
nTop = tMyObject.TOP + tMyObject.HEIGHT + 2
nLeft= tMyObject.LEFT
*// Now I will position my modal form to be a little bit 
*// under the bottom of this control.
ThisForm.TOP  = nTop+27
ThisForm.LEFT = nLeft+4
[Code]

Thanks Walid Magd
Engwam@Hotmail.com
 
The positioning of my calendar form is not the problem - I've got that down. However, my problem is when the date control that calls the form is at the bottom of its own form. I have to set the ShowWindow to be 1 in order for it to appear properly, but if the control is near the bottom, the bottom half of the form is cut off.

I was just wondering what you did (or would do) in this circumstance. I'm considering moving the form to the top of the control, but in reality I want it to resemble a drop down box as much as possible (don't wanna confuse the user!)
 
Hi mpgalvin,

I spent some more time looking at your original question and looked at it from the standpoint of VFP 6.0 -- I assume that's what you are using. V 3.0 doesn't have the ShowWindow property that you are using. In effect I am using ShowWindow 0 (In Screen) This should keep your original form visible while your modal calendar is active. The challenge remains to ensure that your calling form and its associated text/date box do not appear too close to the bottom of the screen -- that will require some design considerations on your part. You might need to limit where a window can be moved and also consider not putting date objects near the bottom of forms. You could also move the calling form just prior to the calendar opening (but that would probably not look too good. What I intended doing for my application was to have the calendar open above or to the side of the object.

I'll be interested in know what you end up with.

-- Chuck Davis
 
Chuck, my problem is the the form which invokes the calendar form is itself in a larger top-level form, so putting the calendar form "in screen" sends the form to the main form, hiding the calling form.

(Woah, that doesn't make much sense, but I hope you understand it).

For the moment, I'm going with the assumption that there will never be a date control right at the bottom of the 'screen' (ie., if the calling form is as big as the main form, and there's a date control at the the bottom of the calling form, I'm in trouble).

I guess it'll come up during QA :-D
 
Hi!

What about good ald mouse functions known from FPD/FPW versions? These are MCOL(), MROW() and MDOWN()...

In the Click event you can get the mouse coordinates using these functions and position your form correctly.

Hope this helps.
Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top