How do I get the position of the text baseline in a Label and a NumericUpDown?
.net, alignment, baseline, c#, winforms
Solution
// to render text with baseline at coordinates (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);
Problem
I'm trying to align a `Label` and a `NumericUpDown` by their text baselines. I'm doing it in code, rather than the designer. How do I get the position of the text baseline?