c# – 如何在Label和NumericUpDown中获取文本基线的位置?

c# – 如何在Label和NumericUpDown中获取文本基线的位置?,第1张

概述我试图通过他们的文本基线对齐一个Label和NumericUpDown.我在代码中做,而不是设计师.如何获取文本基线的位置? //在坐标(pt.X,pt.Y)上渲染带有基线的文本: Font myFont = Label1.Font;FontFamily ff = myFont.FontFamily;float lineSpace = ff.GetLineSpacing(myFont.Sty 我试图通过他们的文本基线对齐一个Label和Numericupdown.我在代码中做,而不是设计师.如何获取文本基线的位置?解决方法 //在坐标(pt.X,pt.Y)上渲染带有基线的文本:
Font myFont = Label1.Font;FontFamily ff = myFont.FontFamily;float linespace = ff.Getlinespacing(myFont.Style);float ascent = ff.GetCellAscent(myFont.Style);float baseline =  myFont.GetHeight(ev.Graphics) * ascent / linespace;PointF renderPt = new PointF(pt.X,pt.Y  - baseline));ev.Graphics.DrawString("Render this string",myFont,textBrush,renderPt);
总结

以上是内存溢出为你收集整理的c# – 如何在Label和NumericUpDown中获取文本基线的位置?全部内容,希望文章能够帮你解决c# – 如何在Label和NumericUpDown中获取文本基线的位置?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1257771.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存