public static void Render(TextBox textBox, List <Paragraph> paragraphs, Win32DCSafeHandle hdc, FontCache fontCache, PointF offset, RectangleF layoutRectangle, float dpiX, bool unitsInMM) { if (paragraphs != null && paragraphs.Count != 0) { Rectangle layoutRectangle2; Point point; if (unitsInMM) { layoutRectangle2 = new Rectangle(TextBox.ConvertToPixels(layoutRectangle.X, dpiX), TextBox.ConvertToPixels(layoutRectangle.Y, dpiX), TextBox.ConvertToPixels(layoutRectangle.Width, dpiX), TextBox.ConvertToPixels(layoutRectangle.Height, dpiX)); point = new Point(TextBox.ConvertToPixels(offset.X, dpiX), TextBox.ConvertToPixels(offset.Y, dpiX)); } else { layoutRectangle2 = new Rectangle((int)layoutRectangle.X, (int)layoutRectangle.Y, (int)layoutRectangle.Width, (int)layoutRectangle.Height); point = new Point((int)offset.X, (int)offset.Y); } uint fMode = Win32.SetTextAlign(hdc, 24u); int iBkMode = Win32.SetBkMode(hdc, 1); Win32ObjectSafeHandle win32ObjectSafeHandle = Win32.SelectObject(hdc, Win32ObjectSafeHandle.Zero); try { fontCache.WritingMode = textBox.TextBoxProps.WritingMode; int y = point.Y; for (int i = 0; i < paragraphs.Count; i++) { TextBox.RenderParagraph(textBox, paragraphs[i], hdc, fontCache, point.X, ref y, layoutRectangle2, dpiX); } } finally { fMode = Win32.SetTextAlign(hdc, fMode); iBkMode = Win32.SetBkMode(hdc, iBkMode); if (!win32ObjectSafeHandle.IsInvalid) { Win32ObjectSafeHandle win32ObjectSafeHandle2 = Win32.SelectObject(hdc, win32ObjectSafeHandle); win32ObjectSafeHandle2.SetHandleAsInvalid(); win32ObjectSafeHandle.SetHandleAsInvalid(); } } } }