public static int GetTextBaseline(Control ctrl, ContentAlignment alignment) { Rectangle clientRectangle = ctrl.ClientRectangle; int num = 0; int tmHeight = 0; using (Graphics graphics = ctrl.CreateGraphics()) { IntPtr hdc = graphics.GetHdc(); IntPtr handle = ctrl.Font.ToHfont(); try { IntPtr ptr3 = System.Design.SafeNativeMethods.SelectObject(new HandleRef(ctrl, hdc), new HandleRef(ctrl, handle)); System.Design.NativeMethods.TEXTMETRIC tm = new System.Design.NativeMethods.TEXTMETRIC(); System.Design.SafeNativeMethods.GetTextMetrics(new HandleRef(ctrl, hdc), tm); num = tm.tmAscent + 1; tmHeight = tm.tmHeight; System.Design.SafeNativeMethods.SelectObject(new HandleRef(ctrl, hdc), new HandleRef(ctrl, ptr3)); } finally { System.Design.SafeNativeMethods.DeleteObject(new HandleRef(ctrl.Font, handle)); graphics.ReleaseHdc(hdc); } } if ((alignment & anyTopAlignment) != ((ContentAlignment)0)) { return(clientRectangle.Top + num); } if ((alignment & anyMiddleAlignment) != ((ContentAlignment)0)) { return(((clientRectangle.Top + (clientRectangle.Height / 2)) - (tmHeight / 2)) + num); } return((clientRectangle.Bottom - tmHeight) + num); }
public static int GetTextBaseline(Control ctrl, ContentAlignment alignment) { Rectangle clientRectangle = ctrl.ClientRectangle; int num = 0; int tmHeight = 0; using (Graphics graphics = ctrl.CreateGraphics()) { IntPtr hdc = graphics.GetHdc(); IntPtr handle = ctrl.Font.ToHfont(); try { IntPtr ptr3 = System.Design.SafeNativeMethods.SelectObject(new HandleRef(ctrl, hdc), new HandleRef(ctrl, handle)); System.Design.NativeMethods.TEXTMETRIC tm = new System.Design.NativeMethods.TEXTMETRIC(); System.Design.SafeNativeMethods.GetTextMetrics(new HandleRef(ctrl, hdc), tm); num = tm.tmAscent + 1; tmHeight = tm.tmHeight; System.Design.SafeNativeMethods.SelectObject(new HandleRef(ctrl, hdc), new HandleRef(ctrl, ptr3)); } finally { System.Design.SafeNativeMethods.DeleteObject(new HandleRef(ctrl.Font, handle)); graphics.ReleaseHdc(hdc); } } if ((alignment & anyTopAlignment) != ((ContentAlignment) 0)) { return (clientRectangle.Top + num); } if ((alignment & anyMiddleAlignment) != ((ContentAlignment) 0)) { return (((clientRectangle.Top + (clientRectangle.Height / 2)) - (tmHeight / 2)) + num); } return ((clientRectangle.Bottom - tmHeight) + num); }
public static extern bool GetTextMetrics(HandleRef hdc, System.Design.NativeMethods.TEXTMETRIC tm);