Thank You for your help!
Tried this and now I got the next problem. It's not a problem of FlowChart, but perhaps someone can help anyway.
Microsoft's RichTextBox control has no direct method for painting or printing. There is an article at MSDN that shows how to print anyway by using some window messages.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwinforms/html...I tried to adapt that VB function for using it to draw on the Graphics within the PaintControlHost event. It's working somehow, but the scaling doesn't fit. The boxes have wrong size and appear in wrong place and it doesn't seem to be a linear offset. By just multiplying the Rects with some factor you can achieve to fit one RichTextBox in the correct place, but not the others.
Perhaps someone can help? ???
The PaintControlHost event:
private void flowChart1_PaintControlHost(object sender, ControlPaintArgs e) {
if (e.ControlHost.Control is ExtendedRichTextBox.RichTextBoxPrintCtrl) {
ExtendedRichTextBox.RichTextBoxPrintCtrl rtb = (ExtendedRichTextBox.RichTextBoxPrintCtrl) e.ControlHost.Control;
rtb.GetImage(e.Graphics, e.PaintRect, flowChart1.DocExtents);
}
}
The adpated VB function:
' Render the contents of the RichTextBox for printing
' Return the last character printed + 1 (printing start from this point
for next page)
Public Function GetImage(ByVal e As Graphics, ByVal drawrect As
RectangleF, ByVal devRect As RectangleF) As Integer
' Mark starting and ending character
Dim cRange As CHARRANGE
cRange.cpMin = 0
cRange.cpMax = Me.TextLength - 1
' Calculate the area to render and print
Dim rectToPrint As RECT
rectToPrint.Top = drawrect.Top * AnInch
rectToPrint.Bottom = drawrect.Bottom * AnInch
rectToPrint.Left = drawrect.Left * AnInch
rectToPrint.Right = drawrect.Right * AnInch
' Calculate the size of the page
Dim rectPage As RECT
rectPage.Top = devRect.Top * AnInch
rectPage.Bottom = devRect.Bottom * AnInch
rectPage.Left = devRect.Left * AnInch
rectPage.Right = devRect.Right * AnInch
Dim hdc As IntPtr = e.GetHdc()
Dim fmtRange As FORMATRANGE
fmtRange.chrg = cRange ' Indicate character from to
character to
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 whole size of page
Dim res As IntPtr = IntPtr.Zero
Dim wparam As IntPtr = IntPtr.Zero
wparam = New IntPtr(1)
' Move the pointer to the FORMATRANGE structure in memory
Dim lparam As IntPtr = 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
e.ReleaseHdc(hdc)
' Return last + 1 character printer
Return res.ToInt32()
End Function