我想获得文本基线和C#中标签底边之间的确切距离。 我想要这个因为我想在文本下画一条线(不想使用带下划线的字体,因为它非常紧密/接近文本)。
这是我的尝试:
//This is placed in the custom label class int dy = (int)((ClientRectangle.Height - Font.GetHeight())/2);但这并不准确,dy返回约3,绘制到标签的线距离文本的基线太远。
I want to get the exact distance between the baseline of the text and the bottom border of a label in C#. I want this because I want to draw a line under the text (don't want to use underlined font, because it's so tight/close to the text).
Here is my try:
//This is placed in the custom label class int dy = (int)((ClientRectangle.Height - Font.GetHeight())/2);But it's not exact, the dy returns about 3 and the line drawn to the label is too far from the baseline of the text.
最满意答案
要获取标签的文本基线,假设您在自定义标签类中,在绘图处理程序中。
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;信用就在这里 。
To get text baseline for a label, assuming you are inside the custom label class, in the drawing handler.
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;Credit goes here.
更多推荐
文本,text,dy,label,want,电脑培训,计算机培训,IT培训"/> <meta name="descrip
发布评论