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!

From pixels to Row and Columns 1

Status
Not open for further replies.

Peter.T.

Programmer
Jun 29, 2022
5
0
0
GB
Someone asked a question "how do I go from pixels to Rows and Columns?"

I wanted to display the output from a wait message near to the label the user has just clicked. Here is my solution -
If anyone is still crazzy enough to be programming in Fox - I hope this helps

---------------------------------------------------------------------------------------------------
LOCAL lcTargetForm

nChrHeight = FONTMETRIC(1) && Chr height
nChrWidth = FONTMETRIC(6) && average Chr width

nRow = INT(this.top / nChrHeight) + 1
ncol = INT(this.Left / nChrWidth) + 1

IF EMPTY(THIS.targetform )
WAIT WINDOW 'Not available ' AT nRow,nCol && almost AT ROW(),COL()
RETURN
ELSE
lcTargetForm = THIS.targetform
DO FORM (lcTargetForm)
ENDIF
--------------------------------------------------------------------------------------------------
 
Hello Peter and welcome to the forum. Good to see that your first contribution is a helpful tip.

Just to make sure I have understood it right: Are you saying that this code would be in the click of event of a label? And when the user clicks the label, they will see a certain form, if the form is specified in a property of the label(THIS.targetform)? And if no such form is specified, they will see a wait window at approximately the label's position?

Is that right? If not, perhaps you could clarify it.

A couple of other comments.

- When posting program code in the forum, you can improve its appearance by using the method which I explained in thread184-1817705.

- You are courting danger by accusing us of being "crazy enough to be programming in Fox". Then again, maybe you are right. Maybe we are all crazy.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
On the thisForm, there's a .scaleMode property. It defaults to 3 - Pixels, but if you set it to 0 - Foxels, it will work in character coordinates. This mimics the @ Y,X SAY command.

Code:
* Type these in the command window, or single-step through them:
_screen.scaleMode = 0                     && Set to foxels
_screen.AddObject("lblTest", "label")     && Adds a default label
_screen.lblTest.Visible = .t.             && Show it in the upper-left
_screen.lblTest.Left    = 2               && Move X to 2, which is 2 foxels, not 2 pixels
_screen.lblTest.Top     = 2               && Same here for Y

--
Rick C. Hodgin
 
Hi Mike,Rick

Yes - I put labels on the form and underline them so that they look like hyperlinks. If I have developed the form, and put its name in the property, then it will bring up the form but if I am still working on the form then it just says that it is 'unavailable'. I try to keep it simple. I let Foxpro handle the forms and keep each with its own private data session. "On shutdown" code triggers in the form if the app is closed. That way I do not need lots of code to handle forms and everything works fine. The wait window error responses are displayed near to the label that was clicked by the user, and that is helpful.

I like Rick's solution as well but prefer to keep the original scale so that I have pixel level positioning if I need it!
 
Load the debugger and add the thisForm.label's left, top, width, and height properties to the Watch window. And also the thisForm.scaleMode property.

Change scaleMode from 3 to 0 to 3 and watch those label properties.

--
Rick C. Hodgin
 
Hi Rick

I wanted to know dynamically where the label was so that I had generic code to put the message there. As the property is in pixels I was looking for a way to convert the pixel position into rows and columns. Thank you for your post - most helpful

Peter
 
Peter,

I've done something similar myself, but it didn't involve converting pixels to rows or columns. I did the whole thing in pixels.

Here is the core of my code:

Code:
lnLeft = OBJTOCLIENT(this, 2) + OBJTOCLIENT(thisform, 2)  - _screen.left
lnTop =  OBJTOCLIENT(this, 1) + OBJTOCLIENT(thisform, 1)  - _screen.top

That will give you the position of the label relative to the containing form. You can then pass those values to the called form, which will use them to set its own Top and Left. All measurements are in pixels.

To make the label look more like a hyperlink, as well as underlining it, I set its FontColor to RGB(0, 0, 255) (blue) and its MousePointer to 15 (hand).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
As Rick's suggestion and formatted as Mike likes!

An alternative

Code:
* (Peter Tck-Tips   2022-07-08 12:22)

LOCAL nRow,nCol,lcTargetForm

IF  EMPTY(THIS.targetform )
   THISFORM.SCALEMODE = 0  			&& Foxels
   nRow = THIS.TOP + 1
   nCol = THIS.LEFT + 1
   WAIT WINDOW 'Not available '  AT nRow,nCol 	&& almost AT ROW(),COL()
   THISFORM.SCALEMODE = 3  			&& back to pixels
   RETURN
ELSE
   lcTargetForm = THIS.targetform
   DO FORM (lcTargetForm)
ENDIF
 
Mike - thanks for the mouse pointer tip. I missed that. I do colour it blue (sorry color it)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top