나는 어떻게 위치를 텍스트의 기준선에서 레이블 및 NumericUpDown?
문제
하려고 해요 정렬 Label
고 NumericUpDown
에 의해 자신의 텍스트 기준을.나는 그것을 하고 있는 코드에서,보다는 오히려 디자이너입니다.어떻게 받을 수 있는 텍스트의 위치는 기준?
해결책
//으로 텍스트를 렌더링하는 기준에 좌표(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);
다른 팁
레이블에 대한 제한,당신이 얻을 수 있는 위치의 텍스트의 맨 아래로 이 방법:
가정.TextAlign 설정하면 좌측상 또는 TopCenter 또는 TopRight,텍스트의 맨 아래에서 레이블을 제어할 수 있습을 발견에 의해 이 방법:
dim btmOfText as single
btmOfText = Label1.Font.GetHeight + Label1.Top
니다.GetHeight 방법을 반환합니다 높이를 픽셀 단위의 현재 글꼴을 사용하여 레이블이 있습니다.
는 경우.TextAlign 중간이나 아래쪽에,당신이해야 할 조금 더 복잡한 계산이 됩니다.
이 같은 방법을 또한 작업 NumericUpDown 제어합니다.
제휴하지 않습니다 StackOverflow