- clipz.zip
- Clipz.sln
- Clipz
- Core
- AppRestartRecovery
- Core.csproj
- Dialogs
- Common
- TaskDialogs
- Interop
- NetworkList
- PowerManagement
- Properties
- PropertySystem
- SafeHandles
- Libraries
- StructureMap.dll
- Shell
- Common
- CommonFileDialogs
- Controls
- Design
- ShellObjects.cd
- ShellThumbnailClassDiagram.cd
- DesktopWindowManager
- ExplorerBrowser
- Interop
- Common
- Dialogs
- ExplorerBrowser
- KnownFolders
- PropertySystem
- StockIcons
- Taskbar
- KnownFolders
- Properties
- PropertySystem
- Shell.csproj
- StockIcons
- Taskbar
|
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Clipz.NativeMethods;
namespace Clipz
{
public class RichTextHost : RichTextBox
{
private const double Inch = 14.4; // represents one inch
public int Print(int charFrom, int charTo, Graphics gr, Rectangle bounds)
{
RECT rectToPrint;
rectToPrint.Top = 0;
rectToPrint.Bottom = (int)(bounds.Height * Inch);
rectToPrint.Left = 0;
rectToPrint.Right = (int)(bounds.Width * Inch);
RECT rectPage;
rectPage.Top = 0;
rectPage.Bottom = (int)(gr.ClipBounds.Height * Inch);
rectPage.Left = 0;
rectPage.Right = (int)(gr.ClipBounds.Right * Inch);
var hdc = gr.GetHdc();
FORMATRANGE fmtRange;
fmtRange.chrg.cpMax = charTo;
fmtRange.chrg.cpMin = charFrom;
fmtRange.hdc = hdc;
fmtRange.hdcTarget = hdc;
fmtRange.rc = rectToPrint;
fmtRange.rcPage = rectPage;
var res = IntPtr.Zero;
var wparam = IntPtr.Zero;
wparam = new IntPtr(1);
var lparam = IntPtr.Zero;
lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fmtRange));
Marshal.StructureToPtr(fmtRange, lparam, false);
// Send the rendered data for 'printing'
res = User32.SendMessage(Handle, (int)WindowsMessages.EM_FORMATRANGE, wparam, lparam);
Marshal.FreeCoTaskMem(lparam);
gr.ReleaseHdc(hdc);
return res.ToInt32();
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm the founder of PageLabs, a web-based performance and SEO optimization site.
Give your site a boost in performance, even take a free speed test!
http://www.pagelabs.com