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

From pixels to Row and Columns

Status
Not open for further replies.

billyhs

Programmer
Jul 28, 2004
11
ID
Hello everyone,

does anybody know how to convert from X,Y pixels location to Row and Column, in a Form ?
I have a situation where I want to put up a shortcut menu at the location of my label control. The label has Left and Top positions in pixels, but the popup menu takes Row and Col positions.

Thanks in advance for your help.

Billy.
 
Billy,

I know this doesn't answer your question. But the usual way to do shortcut menus is to place them in the right-click event of the relevant control. In other words, if you put this code in the right-click of the label:

DO MyShortcut.MPR

you will see the menu pop up on the label, without you having to specify the row or column. Of course, the user has to know to right-click in order to see the menu.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Hmm, well in the good old days we used to use the fontmetric() function to return the Average character width in pixels and calculate the number of chrs we could fit in the given pixel area thereby returning the col and the Character height in pixels the same way. But someone else may have another suggestion.

'Old code programmers never die they just sit back and wonder how they ever did it!'

Bob Palmer
The most common solution is H2O!
 
Billy,
The real problem is that Row/Column is a concpt leftover from the DOS days. How many "rows and columns" there are on a given form, depends on the current font settings for that form. Mike's suggestion is what you do in a Windows app.

Rick
 
Thank you all for answering my question.
I have tried Mike' suggestion, however the menu showed up at the pointer location which could be anywhere on the label control.
What I really want is to display that menu at a fixed position which is somewhere on the left edge of my label.
In any case, thanks again for your valuable suggestions.
 
I've copied the following code that I use in the RighClick event of a textbox that expects a date value. The code determines where the text box is on the form and then opens a date picker form in an appropriate location near the text box. It's kind of primitive, but you might be able to play with the concepts to do what you are trying to do.

nXCoord = This.Parent.Left + This.Left + 2
nYCoord = This.Parent.Top + This.Top + This.Height + 25

If nYCoord >= 320 && Move Calendar Above Textbox
nYCoord = nYCoord - 140 && Height of Calendar Form
nYCoord = nYCoord - ((This.Height * 2)+5)
Endif
If nXCoord >= 620 && Shift Calendar Left
nXCoord = nXCoord - (140-This.Width) && Width of Calendar Form
Endif

DO FORM Calendar.scx WITH (This.Value),nXCoord,nYCoord
This.Value = mydate
RELEASE mydate


CDavis
 
Thank you CDavis for your code sample.
I have tried to combine everyone's suggestions and been able to come up with a solution which works for me.

Billy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top