我正在尝试使用WPF RichTextBox来精确地容纳特定等宽字体中的字符网格.我目前正在使用FormattedText来确定我的RichTextBox的宽度和高度,但它为我提供的测量值太小 - 特别是两个宽度太小的字符.
有没有更好的方法来执行此任务?这似乎不是确定我的控件大小的合适方法.
RichTextBox rtb;
rtb = new RichTextBox();
FontFamily fontFamily = new FontFamily("Consolas");
double fontSize = 16;
char standardizationCharacter = 'X';
String standardizationLine = "";
for(long loop = 0; loop < columns; loop ++) {
standardizationLine += standardizationCharacter;
}
standardizationLine += Environment.NewLine;
String standardizationString = "";
for(long loop = 0; loop < rows; loop ++) {
standardizationString += standardizationLine;
}
Typeface typeface = new Typeface(fontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
FormattedText formattedText = new FormattedText(standardizationString, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, fontSize, …Run Code Online (Sandbox Code Playgroud)