Draw rtf on user control
-
I need to create control that accepts rtf and draws it. Problem is that drawstring takes only regular text and I cant find anywhere how to draw rtf. Any sugestions are welcome and appreciated...
draw rtf :confused: Have a look at 'RichTextBox' (that's a standard control)
-
draw rtf :confused: Have a look at 'RichTextBox' (that's a standard control)
-
Yes I know about richtextbox.. and load and save rtf etc. Please read post again. I need to draw rtf on user control. But thanks anyway.
You'll have explain a bit better what you mean with 'draw rtf'. I don't really see the point in actually painting the text onto a usercontrol when the richttextbox (that you can drop onto a usercontrol) would accomplish all this for you. (if you don't want users to alter the text just set it to disabled or read-only)
-
I need to create control that accepts rtf and draws it. Problem is that drawstring takes only regular text and I cant find anywhere how to draw rtf. Any sugestions are welcome and appreciated...
Try using RichTextBox.DrawToBitmap, then rendering the bitmap. It's not perfect (it only draws the borders of embedded images), but suffices for a managed solution. I think you could use a method which draws a window (and by extension, control) image to a HDC, but I can't remember the name right now
-
Try using RichTextBox.DrawToBitmap, then rendering the bitmap. It's not perfect (it only draws the borders of embedded images), but suffices for a managed solution. I think you could use a method which draws a window (and by extension, control) image to a HDC, but I can't remember the name right now
Hi, Conceptually OK, however a few days ago I learned RichTextBox.DrawToBitmap() does not really work. I solved that by creating my own method, based on FormatRange, see here[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
Hi, Conceptually OK, however a few days ago I learned RichTextBox.DrawToBitmap() does not really work. I solved that by creating my own method, based on FormatRange, see here[^]. :)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
That's very clever. Did you print to another HDC instead of the one given by PrintPageEventArgs, or use another method?
public void DrawToBitmap(Bitmap bitmap) {
//Calculate the area to render and print
RECT rectToPrint;
rectToPrint.Top = 0;
rectToPrint.Bottom = (int)(bitmap.Height*anInch);
rectToPrint.Left = 0;
rectToPrint.Right = (int)(bitmap.Width*anInch);//Calculate the size of the page RECT rectPage; rectPage.Top = 0; rectPage.Bottom = (int)(bitmap.Height\*anInch); rectPage.Left = 0; rectPage.Right = (int)(bitmap.Width\*anInch); Graphics g=Graphics.FromImage(bitmap); IntPtr hdc = g.GetHdc(); FORMATRANGE fmtRange; // \[0,-1\]=everything fmtRange.chrg.cpMax = -1; //Indicate character from to character to fmtRange.chrg.cpMin = 0; fmtRange.hdc = hdc; //Use the same DC for measuring and rendering fmtRange.hdcTarget = hdc; //Point at printer hDC fmtRange.rc = rectToPrint; //Indicate the area on page to print fmtRange.rcPage = rectPage; //Indicate size of page IntPtr res = IntPtr.Zero; IntPtr wparam = IntPtr.Zero; wparam = new IntPtr(1); //Get the pointer to the FORMATRANGE structure in memory IntPtr lparam= IntPtr.Zero; lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange)); Marshal.StructureToPtr(fmtRange, lparam, false); //Send the rendered data for printing res = SendMessage(Handle, EM\_FORMATRANGE, wparam, lparam); //Free the block of memory allocated Marshal.FreeCoTaskMem(lparam); //Release the device context handle obtained by a previous call g.ReleaseHdc(hdc);
}
:)
Luc Pattyn [Forum Guidelines] [My Articles]
Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in
-
I need to create control that accepts rtf and draws it. Problem is that drawstring takes only regular text and I cant find anywhere how to draw rtf. Any sugestions are welcome and appreciated...
First of all I want to thank you all for replying to this topic... But disscusion went in te wrong way. What I wanted is not any use of richtextbox, but method similiar to Graphics.Drawstring method that takes rtf instead of string and paints it on user control. Since there is no provided splution I guess I have to try to wirte some kind of parser that takes tekst and formating for it an use Graphics.Drawstring method...
-
First of all I want to thank you all for replying to this topic... But disscusion went in te wrong way. What I wanted is not any use of richtextbox, but method similiar to Graphics.Drawstring method that takes rtf instead of string and paints it on user control. Since there is no provided splution I guess I have to try to wirte some kind of parser that takes tekst and formating for it an use Graphics.Drawstring method...
I think you may want some of the stuff in here: http://msdn.microsoft.com/en-us/library/cc656574(VS.85).aspx[^] and http://msdn.microsoft.com/en-us/library/cc656564(VS.85).aspx[^] and ITextDocument::Open[^] I have used this (the code is in C++ but it may give you some ideas) here: Win32TextPeer.cpp[^] You an create an ITextDocument, open your RTF, then use the TextServices to render the ITextDocument to an HDC.
¡El diablo está en mis pantalones! ¡Mire, mire! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! Personal 3D projects Just Say No to Web 2 Point Oh
-
I think you may want some of the stuff in here: http://msdn.microsoft.com/en-us/library/cc656574(VS.85).aspx[^] and http://msdn.microsoft.com/en-us/library/cc656564(VS.85).aspx[^] and ITextDocument::Open[^] I have used this (the code is in C++ but it may give you some ideas) here: Win32TextPeer.cpp[^] You an create an ITextDocument, open your RTF, then use the TextServices to render the ITextDocument to an HDC.
¡El diablo está en mis pantalones! ¡Mire, mire! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF! Personal 3D projects Just Say No to Web 2 Point Oh