none
How to measure the font's width and heigth for the current character before its drawing on Canvas WPF?

    Question

  • Hi!
    How to measure the font's width and heigth in pixels for the current character before its drawing on Canvas WPF?
    Thanks for the help.


    Monday, March 31, 2008 1:10 PM

Answers

  • I found this:

     
    Code Snippet

    FormattedText formattedText = new FormattedText(
                    textBox1.Text.Substring(0, 1), 
                    CultureInfo.GetCultureInfo("en-us"),
                    FlowDirection.LeftToRight,
                    new Typeface(textBox1.FontFamily.ToString()),
                     textBox1.FontSize,
                    Brushes.Black
                    );

      ... formattedText.WidthIncludingTrailingWhitespace;
      ... formattedText.Height;



    And I use it now. Thanks all.
    Monday, March 31, 2008 4:50 PM