Winforms to WPF, measure text width(Graphics.MeasureCharacterRanges) -


we trying measure width of text, displayed (not number of characters).

in winforms there method called grapihcs.measurecharacterranges. in wpf, formattedtext.widthincludingtrailingwhitespace. while seem these give same value, don't. why not? graphics.measurecharacterranges, can't pullin winforms, 1 method. wpf app.

we using following utility class perform simple text measurements in wpf:

public static class textutilities {     public static size measuretext(string text,         fontfamily family, double size, fontstyle style, fontweight weight, fontstretch stretch, textformattingmode formattingmode)     {         formattedtext formattedtext = new formattedtext(             text,             cultureinfo.currentculture,             flowdirection.lefttoright,             new typeface(family, style, weight, stretch),             size,             brushes.black,             null,             formattingmode);          return new size(formattedtext.width, formattedtext.height);     }      public static size measuretext(string text, textblock textblock)     {         return measuretext(text,                     textblock.fontfamily,                     textblock.fontsize,                     textblock.fontstyle,                     textblock.fontweight,                     textblock.fontstretch,                     textoptions.gettextformattingmode(textblock));     }       public static size measuretext(string text, control control)     {         return measuretext(text, control.fontfamily, control.fontsize,             control.fontstyle, control.fontweight, control.fontstretch,             textoptions.gettextformattingmode(control));     } } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -