Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VFP FontMetric Equivalent in C# Code
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01406184
Message ID:
01406189
Vues:
57
Take a look at Graphics.MeasureString

>Anyone have any idea how to do this in C#? I need a c# equivalent to fontmetric(). We are adjusting text to fit within an editbox so the lines get broken in appropriate places (inserting carriage returns where we want them so it doesn't adjust on it's own and break it up inappropriately):
>
>(Code below only to show how we are using fontmetric())
>
>Thisform.txtorderby is an editbox.
>Thisform.plorderbycat just allows for 5 spaces for a category to be included such as [123] before each list on each line.
>
>VFP Code:
>
>
>lcNewValue = “ABC, DDC, [S1] AlV, GKL,"
>lcTempOrder = "[S2] DCC, KLB”  && if won't fit on one line, wrap in appropriate place
>
>* If it won't fit, then break it like this example:
>
>*ABC, DDC
>*[S1] AIV, GKL
>*[S2] DCC, KLB
>nWidth = THISFORM.GetTextWidth(lcTempOrder+lcNewValue, ALLTRIM(Thisform.txtorderby.fontname),THISFORM.txtorderby.fontsize,'')
>IF nWidth > (THISFORM.txtOrderBy.Width - 30) && width of control minus the scrollbar width
>        lcTempOrder = ALLTRIM(lcTempOrder) + IIF(RIGHT(ALLTRIM(lcTempOrder),1)<>',',',','')
>        IF EMPTY(lcNewOrder)
>              lcNewOrder = lcTempOrder
>              IF !CHR(13) $ lcNewValue
>                     lcTempOrder = CHR(13) + IIF(!THISFORM.plOrderByCat,LTRIM(CHRTRAN(lcNewValue,',','')),CHRTRAN(lcNewValue,',',''))
>              ELSE
>                     lcTempOrder = IIF(!THISFORM.plOrderByCat,LTRIM(CHRTRAN(lcNewValue,',','')),CHRTRAN(lcNewValue,',',''))
>              ENDIF
>       ELSE
>              IF !CHR(13) $ lcTempOrder
>                     lcTempOrder = CHR(13) + LTRIM(lcTempOrder)
>                     lcNewOrder = lcNewOrder + lcTempOrder
>                     lcTempOrder = CHR(13) + IIF(!THISFORM.plOrderByCat,LTRIM(CHRTRAN(lcNewValue,',','')),CHRTRAN(lcNewValue,',',''))
>              ELSE
>                     lcNewOrder = lcNewOrder + lcTempOrder
>                     lcTempOrder = CHR(13) + IIF(!THISFORM.plOrderByCat,LTRIM(CHRTRAN(lcNewValue,',','')),CHRTRAN(lcNewValue,',',''))
>              ENDIF
>        ENDIF
> ELSE
>        lcTempOrder = lcTempOrder + LTRIM(lcNewValue)
> ENDIF
>
>PROCEDURE gettextwidth
>LPARAMETERS tc_Text, tc_FontName, tn_FontSize, tc_FontStyle
>   Return ( TxtWidth( tc_Text, tc_FontName, tn_FontSize, tc_FontStyle ) * ;
>       FontMetric( 6, tc_FontName, tn_FontSize, tc_FontStyle ) )
>
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform