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

Calculating offset for MOUSE command

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB
Hi all

I have a container class added to a form at runtime when a user clicks on the equivalent of a combo button.

The container class is a VFP calculator and has a transparent shape covering the entire container.

The purpose of the shape is to allow the user to move the container to wherever it suits on the form using the right mouse.

To facilitate using the left mouse, the following code in the .MouseDown() event is used to send the shape to the back and the MOUSE command is used to click on the various buttons of the calculator, which in turn send the shape back to the front.
Code:
[COLOR=blue]DO CASE
CASE nButton = 1
[tab]THIS.ZOrder(1)
[tab]MOUSE CLICK AT nYCoord, nXCoord PIXELS
CASE nButton = 2

ENDC[/color]
However the actual position of the MOUSE click requires adjustment and the code then needs to be
Code:
[COLOR=blue]DO CASE
CASE nButton = 1
[tab]THIS.ZOrder(1)
[tab]MOUSE CLICK AT nYCoord + 23, nXCoord + 4 PIXELS
CASE nButton = 2

ENDC[/color]
The actual additional pixels required are probably specific to this class and are probably not applicable elsewhere.

Can anyone advise why the offset occurs?

TIA

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Is your shape covering the 'keys' or the entire container?

When I've done this in the past, I've had to adjust for the title bar or header as well as left and right edges of the underlying control.
The X-Y coordinates are always returned for the current control the mouse is over, so if your shape control is send to the back, the mouse coordinates would be returned for whatever control was under the shape.

Make sense?


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Dave

Thanks for your reply

The shape is at 0,0 in the container and covers it entirely.

The individual command buttons in the container are 18 pixels high and 20 pixels wide which doesn't appear to relate to the offset required, unless I'm missing something?.

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 

A workaround is to use the right mouse in the various command buttons and container itself to move the container and dispense with the transparent shape.

Still doesn't answer the original question though. [sad]

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Chris,

I'm not clear what the containership hierarchy is here. Is the calculator located within another form or container, or do you place it directly on the main VFP window?

The reason I ask is that the values of nYCoord and nXCoord that Mousedown() receives are relative to the form, whereas the values required by the MOUSE command are relative to the main window, and is dependent on the main window's font metrics.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike, Tamar

Thanks for your replies.

Although I have since implemented the workaround mentioned earlier for reasons other than this particular issue, Mike's point about the values required by the MOUSE command is valid.

The offset probably equates to the header and left border of the child form in _SCREEN.

The container is added directly to the child form and contains only command buttons and a textbox.

If the code for the MOUSE command had the WINDOW cWindowName parameter added, it would probably resolve the issue.

So used to using a similar technique using the GridHitTest() method with grids without the MOUSE command that it didn't occur to me that there would be this difference.

Note to self - read RTFM in future. [smile]



FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Chris,

I went through a similar head-scratching exercise when I was creating my "command button with a drop-down menu" class. It was similar in that the co-ordinates of the menu are relative to the main window, whereas the command button was located in lower-level container.

I don't remember the details of how I solved it, but if you need any more help with the mouse positioning in your calculator, let me know and I'll dig up the code.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike

Thanks for the offer - the difference in the amount of code required for the workaround versus the original is insignificant.

The workaround directly accesses the controls as opposed to using the MOUSE command so is inherently more robust. [smile]

FAQ184-2483​
Chris [pc2]
PDFcommander.com
motrac.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top