2012-09-18 2 views
0

고정 크기 열 GridTextBlock 몇 개가 있습니다. 즉 Grid 크기는 변경 될 수 있지만 열의 너비는 모두 동일합니다 (예 : 전체 크기의 10 %). 각 열에는 TextBlock이 포함됩니다.여러 TextBlock에 가능한 최대 글꼴 크기 찾기

모든 글꼴의 글꼴 크기는 TextBlock이어야합니다.은 동일해야합니다.

TextBlock 안에있는 모든 텍스트를 볼 수있는 최대 글꼴 크기를 어떻게 찾을 수 있습니까?

답변

0

Graphics.MeasureString Method (String, Font, Int32)을 사용하여 글꼴 크기를 계산할 수 있습니다. 그런 다음 동작 마법을 사용하여 글꼴 크기를 TextBlock에 바인드하십시오.

private void MeasureStringWidth(PaintEventArgs e) 
{ 

    // Set up string. 
    string measureString = "Measure String"; 
    Font stringFont = new Font("Arial", 16); 

    // Set maximum width of string. 
    int stringWidth = 200; 

    // Measure string. 
    SizeF stringSize = new SizeF(); 
    stringSize = e.Graphics.MeasureString(measureString, stringFont, stringWidth); 

    // Draw rectangle representing size of string. 
    e.Graphics.DrawRectangle(new Pen(Color.Red, 1), 0.0F, 0.0F, stringSize.Width, stringSize.Height); 

    // Draw string to screen. 
    e.Graphics.DrawString(measureString, stringFont, Brushes.Black, new PointF(0, 0)); 
}