c# - WPF equivalent to TextRenderer -
I used TextRenderer to measure the length of the string and therefore a proper reason Control size Is there a equivalent in WPF or do I simply TextRendered.MeasureString ?
Thank you, Jishu,
I read the following: I've come to work for me:
/// & lt; Summary & gt; /// Get the required height and width of specified text. Uses FortmmText /// & lt; / Summary & gt; Public Static Size MeasTexthesis (String Text, Fontfamily FontFamily, Fontstyle Font Style, Fontweed Fontweit, Fontstheft Font Stretch, Double Font Size) {Formatted Text Fate = New Formatted Text (Text, Culture Infoc, Contentculture, Flow Direction, Lateroite, New Typeface (Fontfamily , Font styles, fontweit, fontfrechts), font size, brush. LAC); Revert new shape (ft.Width, ft.Height); } /// & lt; Summary & gt; /// Get the required height and width of specified text. Uses glyphs /// & lt; / Summary & gt; Public static size measurement text (string text, fontfamily fontfamily, fontstyle font style, fontwait fontweit, fontfrech font stretch, double font size) {typefaces typeface = new typeface (fontfamily, font style, fontweit, font stretch); Glyph typepeace glyph typeface; If (! TypefaceTragateGiliffeyPhase (Out Glyph Typeface)) Return {Measurement text file (text, fontfamily, font style, font height, font stretch, fontsis); } Double total = 0; Double height = 0; For (int n = 0; n & lt; text.Length; n ++) {ushort glyphIndex = glyphTypeface.CharacterToGlyphMap [text [n]]; Double width = Glyph typeface. Advancewidth [Glyph Index] * Font Size; Double Glyph Heights = Glyph Typeface. Advance Heights [Glyph Index] * Font Size; If (glyphight> height) {height = glyphHeight; } Total with + = width; } Return new shape (total width, height); }
Comments
Post a Comment