我如何获得一个标签和一个的NumericUpDown文字基线的位置? [英] How do I get the position of the text baseline in a Label and a NumericUpDown?
本文介绍了我如何获得一个标签和一个的NumericUpDown文字基线的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想通过自己的文本基线对齐一个标签
和的NumericUpDown
。我做在code,而不是设计师。我如何获取文本基线的位置?
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?
推荐答案
//呈现在坐标(pt.X,pt.Y)文本基线:
// 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);
这篇关于我如何获得一个标签和一个的NumericUpDown文字基线的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文