资源简介
史上最好的C#记事本程序,几乎包含所在功能,其中包括很多人未实现的打印功能......
代码片段和文件信息
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Drawing.Printing;
namespace RichTextBoxPrintCtrl
{
public class RichTextBoxPrintCtrl : RichTextBox
{
//Convert the unit used by the .NET framework (1/100 inch)
//and the unit used by Win32 API calls (twips 1/1440 inch)
private const double anInch = 14.4;
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
[StructLayout(LayoutKind.Sequential)]
private struct CHARRANGE
{
public int cpMin; //First character of range (0 for start of doc)
public int cpMax; //Last character of range (-1 for end of doc)
}
[StructLayout(LayoutKind.Sequential)]
private struct FORMATRANGE
{
public IntPtr hdc; //Actual DC to draw on
public IntPtr hdcTarget; //Target DC for determining text formatting
public RECT rc; //Region of the DC to draw to (in twips)
public RECT rcPage; //Region of the whole DC (page size) (in twips)
public CHARRANGE chrg; //Range of text to draw (see earlier declaration)
}
private const int WM_USER = 0x0400;
private const int EM_FORMATRANGE = WM_USER + 57;
[DllImport(“USER32.dll“)]
private static extern IntPtr SendMessage(IntPtr hWnd int msg IntPtr wp IntPtr lp);
// Render the contents of the RichTextBox for printing
// Return the last character printed + 1 (printing start from this point for next page)
public int Print(int charFrom int charTo PrintPageEventArgs e)
{
//Calculate the area to render and print
RECT rectToPrint;
rectToPrint.Top = (int)(e.MarginBounds.Top * anInch);
rectToPrint.Bottom = (int)(e.MarginBounds.Bottom * anInch);
rectToPrint.Left = (int)(e.MarginBounds.Left * anInch);
rectToPrint.Right = (int)(e.MarginBounds.Right * anInch);
//Calculate the size of the page
RECT rectPage;
rectPage.Top = (int)(e.PageBounds.Top * anInch);
rectPage.Bottom = (int)(e.PageBounds.Bottom * anInch);
rectPage.Left = (int)(e.PageBounds.Left * anInch);
rectPage.Right = (int)(e.PageBounds.Right * anInch);
IntPtr hdc = e.Graphics.GetHdc();
FORMATRANGE fmtRange;
fmtRange.chrg.cpMax = charTo; //Indicate character from to character to
fmtRange.chrg.cpMin = charFrom;
fmtRange.hdc = hdc; //Use the same DC for measuring and rendering
fmtRange.hdcTarget = hdc;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 399 2011-10-13 03:07 BWAcs\app.config
文件 208896 2011-12-06 12:41 BWAcs\bin\Debug\BWAcs.exe
文件 399 2011-10-13 03:07 BWAcs\bin\Debug\BWAcs.exe.config
文件 124416 2011-12-06 12:41 BWAcs\bin\Debug\BWAcs.pdb
文件 5632 2005-12-08 14:51 BWAcs\bin\Debug\BWAcs.vshost.exe
文件 399 2011-10-13 03:07 BWAcs\bin\Debug\BWAcs.vshost.exe.config
文件 8477 2011-11-07 18:09 BWAcs\BWAcs.csproj
文件 4014 2011-11-10 15:27 BWAcs\Class1.cs
文件 59487 2011-12-06 12:41 BWAcs\Form1.cs
文件 88897 2011-11-10 23:12 BWAcs\Form1.Designer.cs
文件 28299 2011-11-10 23:12 BWAcs\Form1.resx
文件 1126 2011-11-09 01:11 BWAcs\Formabout.cs
文件 5980 2011-11-09 01:11 BWAcs\Formabout.Designer.cs
文件 8421 2011-11-09 01:11 BWAcs\Formabout.resx
文件 334 2011-10-08 19:29 BWAcs\Formadd.cs
文件 3044 2011-10-08 19:29 BWAcs\Formadd.Designer.cs
文件 5814 2011-10-08 19:29 BWAcs\Formadd.resx
文件 4287 2011-10-17 14:04 BWAcs\formFind.cs
文件 6958 2011-10-17 08:51 BWAcs\formFind.Designer.cs
文件 8226 2011-10-17 08:51 BWAcs\formFind.resx
文件 2518 2011-11-11 00:14 BWAcs\FormGY.cs
文件 13323 2011-11-11 00:14 BWAcs\FormGY.Designer.cs
文件 8420 2011-11-11 00:14 BWAcs\FormGY.resx
文件 6076 2011-10-17 16:30 BWAcs\formReplace.cs
文件 8988 2011-10-17 16:11 BWAcs\formReplace.Designer.cs
文件 8226 2011-10-17 16:11 BWAcs\formReplace.resx
文件 435 2012-02-08 23:15 BWAcs\obj\BWAcs.csproj.FileList.txt
文件 2460 2011-11-11 00:14 BWAcs\obj\Debug\BWAcs.csproj.GenerateResource.Cache
文件 208896 2011-12-06 12:41 BWAcs\obj\Debug\BWAcs.exe
文件 14132 2011-11-10 23:12 BWAcs\obj\Debug\BWAcs.Form1.resources
............此处省略111个文件信息
评论
共有 条评论