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

Sim*_*mon 10 .net c# alignment baseline winforms

我试图通过他们的文本基线对齐a Label和a NumericUpDown.我是用代码而不是设计师来做的.如何获得文本基线的位置?

dar*_*7yl 14

//在坐标(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);
Run Code Online (Sandbox Code Playgroud)