1

Konu: Güzel bir form örneği.

http://www.foxite.com/forum/read.aspx?id=0000258467

Visual Fox Pro
Public oFOrm

oFOrm = Createobject('Myform','First Name,Last Name,City,State,Zip')
oFOrm.Show
 
** TextMeasure.prg
** Author: Cetin Basoz
Procedure TextMeasure(tcText, tcFontName, tnFontSize, tlBold, tlItalic, tlUnderline)
  Local lnDc,lnPixelsPerInch,lcStyle
  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
 
  #Define WU_LOGPIXELSX  88
  lnDc = GetWindowDC(0)
  lnPixelsPerInch = GetDeviceCaps(lnDc, WU_LOGPIXELSX)
  lnDc = ReleaseDC(0, lnDc)
 
  lcFont = _Screen.FontName && _Screen.FontName
  lnFontSize = _Screen.FontSize
  lcStyle = ;
    Iif(m.tlBold,'B','')+;
    Iif(m.tlItalic,'I','')+;
    Iif(m.tlUnderline,'U','')
  lcStyle = Iif( Empty(m.lcStyle),'N',m.lcStyle)
 
  Return Txtwidth(m.tcText, m.tcFontName, m.tnFontSize,m.lcStyle) * ;
    fontmetric(6, m.tcFontName, m.tnFontSize, m.lcStyle)
Endproc
 
Define Class myForm As Form
  Procedure Init(tcLabels)
    Local Array laLabels[1]
    Local ix,lnLabelWidth,lnWidth
    Local loLabel, loTextbox
    lnLabelWidth = 0
 
    For ix = 1 To Alines(laLabels,m.tcLabels,1,',')
      lnLabelWidth = Max(m.lnLabelWidth, ;
        TextMeasure(laLabels[m.ix], Thisform.FontName,Thisform.FontSize))
 
      This.AddObject('lbl'+Ltrim(Str(m.ix)),'Label')
      This.AddObject('txt'+Ltrim(Str(m.ix)),'Textbox')
 
      loLabel = Getpem(This, 'lbl'+Ltrim(Str(m.ix)))
      loTextbox = Getpem(This, 'txt'+Ltrim(Str(m.ix)))
      With loLabel As Label
        .Left = 5
        .Top = (m.ix-1) * 30 + 5
        .Caption = laLabels[m.ix]
      Endwith
      loTextbox.Top = (m.ix-1) * 30 + 5
      lnWidth = loTextbox.Width
    Endfor
    This.SetAll('Width',m.lnLabelWidth,'Label')
    This.SetAll('Left', m.lnLabelWidth + 5 + 2, 'Textbox')
    This.AddObject('MyGrid','Grid')
 
    This.Height = 410
    With This.MyGrid As Grid
      .Top = 5
      .Left = m.lnLabelWidth + 5 + 2 + m.lnWidth + 10
      .Width = 300
      .Height = 400
      This.Width = .Left + .Width + 5
      .Anchor = 15
    Endwith
 
    This.SetAll('Visible',.T.)
  Endproc
Enddefine

Kodu Foxite den buldum. Daha önce bu türde bir örnek görmediğim için forum a post ettim.

Yine yayıncısının afffına sığınarak.

Birde sorum var: Üstat;

Visual Fox Pro
Procedure TextMeasure()

  tam olarak ne işe yarar?

Uğur
-------------------------------------------------------------------------------------------------------------
Hayat bir bisiklete binmek gibidir. Pedalı çevirmeye devam ettiğiniz sürece düşmezsiniz. Claude Peppeer
Kusuru söylenmeyen adam, ayıbını hüner sanır.  Türk Atasözü

2

Re: Güzel bir form örneği.

textin pixel olarak boyunu ölçüyor sanırım.

Haksızlıklar karşısında susanlar, dilsiz şeytanlardır!
www.metinemre.com

3

Re: Güzel bir form örneği.

Evet. Verilen bir stringin, belli font ile kac pixel olacagini hesapliyor (oradan da kagitta kac cm olcagina kadar hesap yapilabiliyor). Daha iyi anlamak icin oradaki oForm = satirini degistir. Mesela:

Visual Fox Pro
oFOrm = Createobject('Myform','Uzun bir etiket burada,Ad,Soyad')

Koda dikkat edersen, forma onceden konmus hicbir kontrol yok. Senin verdigin basliklarla birer label, onlarin yanina textbox ve en saga bir grid koyuyor. Yerlesim tamamen kodla. Grid bos cunku data yok ortada (tek amaci yerlesimi gostermekti).

4

Re: Güzel bir form örneği.

Bu da benzer bir ornek (bunda daha iyi anlasiliyor):

Visual Fox Pro
** TextMeasure.prg

** Author: Cetin Basoz
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
 
#Define WU_LOGPIXELSX  88
lnDC = GetWindowDC(0)
lnPixelsPerInch = GetDeviceCaps(lnDC, WU_LOGPIXELSX)
lnDC = ReleaseDC(0, lnDC)
 
lcFont = 'Arial' && _Screen.FontName
lnFontSize = _Screen.FontSize
lcStyle = ;
  Iif(_Screen.FontBold,'B','')+;
  Iif(_Screen.FontItalic,'I','')+;
  Iif(_Screen.FontUnderline,'U','')
lcStyle = Iif( Empty(m.lcStyle),'N',m.lcStyle)
lcTextToMeasure = "Sample text"
lnSizeInPixels = Txtwidth(m.lcTextToMeasure, m.lcFont, m.lnFontSize,m.lcStyle) * ;
  fontmetric(6, m.lcFont, m.lnFontSize,m.lcStyle)
lnSizeInTwips = ( m.lnSizeInPixels  / m.lnPixelsPerInch * 1440 )
lnSizeInPoints = m.lnSizeInTwips / 20
lnSizeInInches = m.lnSizeInTwips / 1440
lnSizeInCm = m.lnSizeInTwips / 1440 * 2.54
lnReportUnits = ( m.lnSizeInPixels  / m.lnPixelsPerInch * 10000 )
 
clear
TEXT TO m.lcDisplay TEXTMERGE noshow
Pixels per inch is: <<m.lnPixelsPerInch>>
Font: <<m.lcFont>>, <<m.lnFontSize>>, <<m.lcStyle>>
String "<<m.lcTextToMeasure>>" measures:
In pixels:    <<m.lnSizeInPixels>>
In Twips:    <<m.lnSizeInTwips>>
In points:    <<m.lnSizeInPoints>>
In Inches:    <<m.lnSizeInInches>>
In centimeters:    <<m.lnSizeInCm>>
In report units:    <<m.lnReportUnits>>
endtext
? m.lcDisplay
* 1 Twip = 1/20 point, 567 twips 1 cm ~ 1440/2.54, 1 inch = 72pts = 1440 twips

5

Re: Güzel bir form örneği.

Üstat, ek açıklamalar için teşekkür ederim.

Daha çok fırın ekmeye ihtiyacımız. Dün ve daha önceki günlerde olduğu gibi.

Ellerine sağlık diyorum yine.

Uğur
-------------------------------------------------------------------------------------------------------------
Hayat bir bisiklete binmek gibidir. Pedalı çevirmeye devam ettiğiniz sürece düşmezsiniz. Claude Peppeer
Kusuru söylenmeyen adam, ayıbını hüner sanır.  Türk Atasözü