Reply to comment

Pixels and Foxels

Foxel is a Visual FoxPro term that corresponds to the maximum height and average width of a character in the current font. The row height corresponds to the maximum height of a letter in the current font; the column width corresponds to the average width of a letter in the current font.

Whenever VFP command or function has row or/and column as a parameter, it is expressed in foxels. It can have decimal fractions for precise positioning.

The Fox2pix() and Pix2fox() functions below provide conversion between pixels and foxels.

This is sample code. Add error handling and adjust to your requirements as necessary.

* Convert foxels to pixels
FUNCTION Fox2pix  
LPARAMETER tnFoxels, tlVertical, tcFontName, tnFontSize
* tnFoxels - foxels to convert
* tlVertical - .F./.T. convert horizontal/vertical coordinates
* tcFontName, tnFontSize - use specified font/size 
*       or current form (active output window) font/size, if not specified 
 
LOCAL lnPixels
 
IF PCOUNT() > 2
	lnPixels = tnFoxels * FONTMETRIC(IIF(tlVertical, 1, 6), tcFontName, tnFontSize)
ELSE
	lnpixels = tnFoxels * FONTMETRIC(IIF(tlVertical, 1, 6))
ENDIF	
 
RETURN lnPixels 
*------------------------------------
 
* Convert pixels to foxels 
FUNCTION Pix2fox
LPARAMETER tnPixels, tlVertical, tcFontName, tnFontSize
* tnPixels - pixels to convert
* tlVertical - .F./.T. convert horizontal/vertical coordinates
* tcFontName, tnFontSize - use specified font/size 
*         or current form (active output window) font/size, if not specified 
LOCAL lnFoxels
 
IF PCOUNT() > 2
	lnFoxels = tnPixels/FONTMETRIC(IIF(tlVertical, 1, 6), tcFontName, tnFontSize)
ELSE
	lnFoxels = tnPixels/FONTMETRIC(IIF(tlVertical, 1, 6))
ENDIF	
 
RETURN lnFoxels

Example 1 of using above functions

* Convert Windows Desktop size to foxels and back
? SYSMETRIC(1), Pix2fox(SYSMETRIC(1)), Fox2pix(Pix2fox(SYSMETRIC(1)))
? SYSMETRIC(2), Pix2fox(SYSMETRIC(2), .T.), Fox2pix(Pix2fox(SYSMETRIC(2), .T.), .T.)

Example 2 shows how to use Pix2fox() to correctly position a shortcut menu and WAIT window.

PUBLIC oform1
 
oform1=NEWOBJECT("form1")
oform1.Show
RETURN
 
DEFINE CLASS form1 AS form
 
	Top = 0
	Left = 0
	Caption = "Example of using Pix2fox() UDF"
	Name = "Form1"
 
	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 140, ;
		Left = 145, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Menu", ;
		Name = "Command1"
 
	ADD OBJECT command2 AS commandbutton WITH ;
		Top = 40, ;
		Left = 145, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Wait", ;
		Name = "Command2"
 
	PROCEDURE command1.Click
		LOCAL lnPosX, lnPosY
 
		* Position a shortcut menu at the bottom-right corner of the button
		lnPosX = Pix2fox(This.Left + This.Width, .F.)
		lnPosY = Pix2fox(This.Top + This.Height, .T.)
 
		DEFINE POPUP test SHORTCUT RELATIVE FROM (lnPosY), (lnPosX)
		DEFINE BAR 1 OF test PROMPT "Menu 1" 
		DEFINE BAR 2 OF test PROMPT "Menu 2" 
		DEFINE BAR 3 OF test PROMPT "Menu 3" 
		ACTIVATE POPUP test
	ENDPROC
 
	PROCEDURE command2.Click
		LOCAL lnPosX, lnPosY, lnRow, lnCol
 
		* Position a WAIT WINDOW menu at the bottom-right corner of the button
		lnPosY = _screen.Top + Thisform.Top + SYSMETRIC(4) + SYSMETRIC(9) + This.Top + This.Height
		lnPosX = Thisform.Left + SYSMETRIC(3) + SYSMETRIC(12) + This.Left + This.Width
 
		lnRow = pix2fox(lnPosY, .T.,_screen.Fontname ,_screen.FontSize)
		lnCol = pix2fox(lnPosX, .F.,_screen.Fontname ,_screen.FontSize)
 
		WAIT WINDOW "TEST" AT (lnRow), (lnCol)
	ENDPROC
 
ENDDEFINE

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <java>, <powershell>, <tsql>, <visualfoxpro>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.