gpt4 book ai didi

c# - 如何获取标签和 NumericUpDown 中文本基线的位置?

转载 作者:可可西里 更新时间:2023-11-01 09:02:37 24 4
gpt4 key购买 nike

我正在尝试根据文本基线对齐 LabelNumericUpDown。我是用代码而不是设计师来做的。如何获取文本基线的位置?

最佳答案

//以坐标 (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# - 如何获取标签和 NumericUpDown 中文本基线的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1006069/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com