怎样获得字体的宽度,该如何处理
怎样获得字体的宽度
<TextBlock Text = "全角、半角、中文字符、英文字符、符号">
文本字体(10-72)大小可变,有全角、半角、中文字符、英文字符、符号
我想获取每个字符所占的宽度,可行否?
------解决方案--------------------
方法多了。
WPF和Silverlight共同的方法。
<TextBlock Text = "全角、半角、中文字符、英文字符、符号">
文本字体(10-72)大小可变,有全角、半角、中文字符、英文字符、符号
我想获取每个字符所占的宽度,可行否?
------解决方案--------------------
方法多了。
WPF和Silverlight共同的方法。
- C# code
TextBlock measureTextBlock = new TextBlock(); _measureTextBlock.FontFamily = target.FontFamily; _measureTextBlock.FontSize = target.FontSize; _measureTextBlock.FontStretch = target.FontStretch; _measureTextBlock.FontStyle = target.FontStyle; _measureTextBlock.FontWeight = target.FontWeight; _measureTextBlock.UseLayoutRounding = target.UseLayoutRounding; _measureTextBlock.Text = text; _measureTextBlock.Measure(new Size(double.MaxValue, double.MaxValue)); return new Size(_measureTextBlock.ActualWidth, _measureTextBlock.ActualHeight);
------解决方案--------------------