Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP FontMetric Equivalent in C# Code
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01406184
Message ID:
01406190
Views:
47
Thanks, someone else pointed me to the fontfamily class and the MeasureCharacterRanges methods... I'll look at them all.


>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 ) )
>>
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform