We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Definition of parameters for RichTextPaint.DrawRichText

Thread ID:





38332 Dec 9,2005 06:08 PM UTC Dec 9,2005 08:20 PM UTC WinForms 2
Tags: GridControl
Lori S. Pearsall
Asked On December 9, 2005 06:08 PM UTC

I picked this forum because a search brought up a reference to this method. I''m looking for a definition for the parameters to this method - particularly the three rectangle parameters. Thanks!

Lori S. Pearsall
Replied On December 9, 2005 06:27 PM UTC

A follow-up question ... I''ve played with this method a bit and have set the Graphics object to point to a bitmap so that an image of the rich text is produced. What I''ve noticed is that the Zoom parameter doesn''t make any difference. Setting it to any value just produces "normal-sized" text. What I''m looking for is the ability to produce an image of the "zoomed" text - RichTextBox.ZoomFactor > 1. Thanks again!

Administrator [Syncfusion]
Replied On December 9, 2005 08:20 PM UTC

This method is intended for internal use woithin our library. That is why it is not documented. Here is teh source code for the method. There is a comment to the effect that the zoom factor does not work. public static void DrawRichText(Graphics g, RichTextBox richTextControl, string rtf, bool printing, Rectangle pageBounds, Rectangle targetBounds, Rectangle clipRect, Color backColor, bool wordWrap, int zoom, bool isRightToLeft) { richTextControl.WordWrap = wordWrap; richTextControl.RightToLeft = isRightToLeft ? RightToLeft.Yes : RightToLeft.No; if (IsValidRtf(rtf)) richTextControl.Rtf = rtf; else richTextControl.Text = rtf; richTextControl.CreateControl(); PaintStatic(g, richTextControl, printing, pageBounds, targetBounds, clipRect, backColor, zoom); } public static void PaintStatic(Graphics g, RichTextBox richTextControl, bool printing, Rectangle pageBounds, Rectangle targetBounds, Rectangle clipRect, Color backColor, int zoom) { RectangleF clipBounds = g.ClipBounds; bool clipped = false; if ((int) clipBounds.Top > targetBounds.Top || clipBounds.Left > targetBounds.Left || clipBounds.Bottom < targetBounds.Bottom || clipBounds.Right < targetBounds.Right) { clipped = true; } clipBounds.Intersect(targetBounds); clipBounds.Intersect(pageBounds); if (!clipRect.IsEmpty) clipBounds.Intersect(clipRect); IntPtr hdc = g.GetHdc(); int bkclr = NativeMethods.RGBToCOLORREF(backColor.ToArgb()); int logPixels1 = NativeMethods.GetDeviceCaps(hdc, 88); float f; float f2; if (printing) { IntPtr hdc2 = NativeMethods.GetDC(IntPtr.Zero); int logPixels2 = NativeMethods.GetDeviceCaps(hdc2, 88); NativeMethods.ReleaseDC(IntPtr.Zero, hdc2); NativeMethods.SIZE windowExt; NativeMethods.SIZE viewportExt; const int MM_ANISOTROPIC = 8; // 0x0008 // Just in case there is non-standard DPI setting for screen // we need to zoom the rtf drawing. NativeMethods.SetMapMode(hdc, MM_ANISOTROPIC); NativeMethods.SetWindowExtEx(hdc, 96, 96, out windowExt); NativeMethods.SetViewportExtEx(hdc, logPixels2, logPixels2, out viewportExt); f = 14.4f*96/logPixels2; f2 = 3.0f;//logPixels1*14.4f/logPixels2; } else { f2 = 1.0f; f = 1440f / logPixels1; } NativeMethods.RECT rcPage = new NativeMethods.RECT(pageBounds); NativeMethods.RECT rc = new NativeMethods.RECT(targetBounds); NativeMethods.RECT rcClip = new NativeMethods.RECT(Rectangle.Ceiling(clipBounds)); NativeMethods.RECT rcClipPage = new NativeMethods.RECT(Rectangle.Ceiling(clipBounds)); NativeMethods.RECT rcClipBox = new NativeMethods.RECT(); rcPage.left = (int) (rcPage.left * f); rcPage.top = (int) (rcPage.top *f); rcPage.right = (int) (rcPage.right *f); rcPage.bottom = (int) (rcPage.bottom *f); rc.left = (int) (rc.left * f); rc.top = (int) (rc.top *f); rc.right = (int) (rc.right *f); rc.bottom = (int) (rc.bottom *f); rcClipPage.left = (int) (rcClipPage.left * f); rcClipPage.top = (int) (rcClipPage.top *f); rcClipPage.right = (int) ((rcClipPage.right) *f); rcClipPage.bottom = (int) ((rcClipPage.bottom) *f); rcClip.left = (int) (rcClip.left * f2); rcClip.top = (int) (rcClip.top *f2); rcClip.right = (int) ((rcClip.right) *f2); rcClip.bottom = (int) ((rcClip.bottom) *f2); NativeMethods.FORMATRANGE fr = new NativeMethods.FORMATRANGE(); fr.rcPage = rcPage; fr.rc = rc; // Print as much text as can fit in the cell. NativeMethods.CHARRANGE chrg = new NativeMethods.CHARRANGE(); chrg.cpMin = 0; chrg.cpMax = -1; fr.chrg = chrg; fr.hdcTarget = hdc; fr.hdc = hdc; if (clipped) { NativeMethods.GetClipBox(hdc, ref rcClipBox); NativeMethods.IntersectClipRect(hdc, rcClip.left, rcClip.top, rcClip.right, rcClip.bottom); } // Now, draw the Rtf cell // ZoomFactor does not work // this.ZoomFactor = zoom/100f; // if (printing) // this.ZoomFactor *= 10*logPixelsX/96f; // This fixes back color when drawing to screen. richTextControl.BackColor = Color.FromArgb(255, backColor); // Tried the following but did not have any effect on back color when printing. // When printing it will always stay white ... // // NativeMethods.SetBkColor(hdc, bkclr); // IntPtr hBrush = NativeMethods.CreateSolidBrush(bkclr); // IntPtr hSavedBrush = NativeMethods.SelectObject(hdc, hBrush); // NativeMethods.FillRect(hdc, ref rcClip, hBrush); /* Background Modes */ //#define TRANSPARENT 1 //#define OPAQUE 2 //#define BKMODE_LAST 2 //NativeMethods.SetBkMode(hdc, 2); FormatRange(richTextControl, null, false); // required by RichEdit to clear out cache FormatRange(richTextControl, fr, false); DisplayBand(richTextControl, rcClipPage); FormatRange(richTextControl, null, false); // required by RichEdit to clear out cache if (clipped) { NativeMethods.SelectClipRgn(hdc, IntPtr.Zero); NativeMethods.IntersectClipRect(hdc, rcClipBox.left, rcClipBox.top, rcClipBox.right, rcClipBox.bottom); } //NativeMethods.SelectObject(hdc, hSavedBrush); //NativeMethods.DeleteObject(hBrush); g.ReleaseHdc(hdc); }


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon