我想获得 C# 中文本基线和标签底部边框之间的确切距离。我想要这个,因为我想在文本下画一条线(不想使用带下划线的字体,因为它太紧/接近文本)。
这是我的尝试:
//This is placed in the custom label class
int dy = (int)((ClientRectangle.Height - Font.GetHeight())/2);
但这并不准确,dy 返回大约 3 并且绘制到标签的线距离文本的基线太远。
要获取标签的文本基线,假设您在自定义标签类中,在绘图处理程序中。
Font myFont = this.Font;
FontFamily ff = myFont.FontFamily;
float lineSpace = ff.GetLineSpacing(myFont.Style);
float ascent = ff.GetCellAscent(myFont.Style);
float baseline = myFont.GetHeight(e.Graphics) * ascent / lineSpace;
信用在这里。