用 DrawString 和 FillPath 写字时字体大小不同怎么办?

xiaoxinghappy 2008-10-29 06:14:59
用 Graphics.DrawString 和 Graphics.FillPath 在界面显示字时,相同的字体,FillPath 要小很多,这个怎么办啊?

Graphics g = e.Graphics;
Rectangle rect = this.DisplayRectangle;
// 正常
g.DrawString(text, this.Font, new SolidBrush(Color.Red), rect);

// 相对DrawString要小很多
using (GraphicsPath path = new GraphicsPath())
{
path.AddString(text, base.Font.FontFamily, (int)base.Font.Style,
base.Font.SizeInPoints, rect,
new StringFormat(StringFormatFlags.DisplayFormatControl));
using (Brush lbs = new SolidBrush(Color.Green))
{
g.FillPath(lbs, path);
}
...全文
234 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoxinghappy 2008-10-29
  • 打赏
  • 举报
回复
楼上的兄弟,不是长度,是高度.

自己已经解决了
优途科技 2008-10-29
  • 打赏
  • 举报
回复
计算字体的长度咯。

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧