Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 To: Russell Hill
  Where is Russell Hill?
 Sydney
 Australia
 Russell Hill
 Tags
Subject: RE: Design using Courier New
Thread ID: 209480 Message ID: 209522 # Views: 8 # Ratings: 1
Version: Visual FoxPro 9 Category: General VFP Topics
Date: Monday, December 29, 2008 12:23:39 PM         
   


> Hi all,
>
> I have an application where the chosen font is Courier New.
>
> As this is a fixed-width font, I should be able to design objects' widths more easily.
>
> But how do I relate a table's field size and the font size to the width of various objects?
>
> For example, let's say I have a field in MyTable called SURNAME, which is C(30).
>
> Is it possible to calculate the required width of a TextBox for various font sizes?
>
> Is this the same for columns in a Grid?
>
> Thanks,
>
> Russell.

Russell,
With monospaced fonts it doesn't matter but with proportional fonts the width is dependant on the content (I mean c(30) wouldn't be enough, you would need to use some text).
I had this old code to calculate it in pixels and points:

o = CREATEOBJECT('TextWidthCalculator')
o.GetTextSize('Hello There','Courier New', 12)
? o.oSize.Pixels, o.oSize.Points
o.GetTextSize('Hello There','Arial', 12)
? o.oSize.Pixels, o.oSize.Points

Define Class TextWidthCalculator As Custom
  nPixelsPerInch = 0
  oSize = .Null.

  Procedure Init
    Declare Integer ReleaseDC In Win32Api;
      INTEGER nwnd, Integer hdc
    Declare Integer GetDeviceCaps In Win32API;
      INTEGER hdc, Integer nIndex
    Declare Integer GetWindowDC In Win32API;
      INTEGER HWnd
    Local lnDC,lnSelect

    #Define WU_LOGPIXELSX  88
    lnDC = GetWindowDC(0)
    This.nPixelsPerInch = GetDeviceCaps(lnDC, WU_LOGPIXELSX)
    ReleaseDC(0, lnDC)
    Clear Dlls 'ReleaseDC', 'GetDeviceCaps', 'GetWindowDC'

    lnSelect = Select()
    Create Cursor dummy (Pixels i,Points i)
    Scatter Name This.oSize Blank
    Use
    Select (m.lnSelect)
  Endproc

  Procedure GetTextSize
    Lparameters tcText, tcFont, tnFontSize, tnStyle
    Local lcStyle, lnSizeInPixels
    lcStyle = Iif( Empty(m.tnStyle), 'N',;
      Iif(Bittest(m.tnStyle,0),'B','')+;
      Iif(Bittest(m.tnStyle,1),'I','')+;
      Iif(Bittest(m.tnStyle,2),'U','') )
    With This.oSize
      .Pixels = ;
        Txtwidth(m.tcText, m.tcFont, m.tnFontSize,m.lcStyle) * ;
        Fontmetric(6, m.tcFont, m.tnFontSize,m.lcStyle)
      .Points = ( .Pixels  / This.nPixelsPerInch * 1440 ) / 20
    Endwith
    Return This.oSize
    * 1 Twip = 1/20 point, 567 twips 1 cm
  Endproc
Enddefine

Cetin Basoz

ENTIRE THREAD

Design using Courier New Posted by Russell Hill @ 12/29/2008 8:55:58 AM
RE: Design using Courier New Posted by Samir Ibrahim @ 12/29/2008 9:47:24 AM
RE: Design using Courier New Posted by Russell Hill @ 12/29/2008 12:24:49 PM
RE: Design using Courier New Posted by Mike Yearwood @ 12/29/2008 7:58:23 PM
RE: Design using Courier New Posted by Samir Ibrahim @ 12/30/2008 10:32:13 AM
RE: Design using Courier New Posted by Stefan Wuebbe @ 12/30/2008 10:46:07 AM
RE: Design using Courier New Posted by Stefan Wuebbe @ 12/29/2008 9:49:08 AM
RE: Design using Courier New Posted by Russell Hill @ 12/29/2008 12:23:04 PM
RE: Design using Courier New Posted by Stefan Wuebbe @ 12/29/2008 5:49:35 PM
RE: Design using Courier New Posted by Russell Hill @ 12/31/2008 1:54:57 AM
RE: Design using Courier New Posted by Gerrit Masee @ 12/29/2008 10:33:40 AM
RE: Design using Courier New Posted by Russell Hill @ 12/29/2008 12:29:21 PM
RE: Design using Courier New Posted by Cetin Basoz @ 12/29/2008 12:23:39 PM
RE: Design using Courier New Posted by Russell Hill @ 12/29/2008 12:27:04 PM
RE: Design using Courier New Posted by tushar @ 12/29/2008 1:18:59 PM
RE: Design using Courier New Posted by Yousfi Benameur @ 12/29/2008 5:12:38 PM
RE: Design using Courier New Posted by Russell Hill @ 12/30/2008 6:11:13 AM
RE: Design using Courier New Posted by Yousfi Benameur @ 12/30/2008 2:41:53 PM
RE: Design using Courier New Posted by Russell Hill @ 12/31/2008 1:54:13 AM
RE: Design using Courier New Posted by Yousfi Benameur @ 12/31/2008 10:16:43 AM
RE: Design using Courier New Posted by Yousfi Benameur @ 12/30/2008 12:14:50 AM
RE: Design using Courier New Posted by Russell Hill @ 12/30/2008 4:12:26 AM
RE: Design using Courier New Posted by Andy Kramek @ 12/31/2008 11:54:33 AM
RE: Design using Courier New Posted by Yousfi Benameur @ 12/31/2008 12:33:17 PM