史上最好的C#记事本


史上最好的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  BWAcsapp.config

     文件     208896  2011-12-06 12:41  BWAcsinDebugBWAcs.exe

     文件        399  2011-10-13 03:07  BWAcsinDebugBWAcs.exe.config

     文件     124416  2011-12-06 12:41  BWAcsinDebugBWAcs.pdb

     文件       5632  2005-12-08 14:51  BWAcsinDebugBWAcs.vshost.exe

     文件        399  2011-10-13 03:07  BWAcsinDebugBWAcs.vshost.exe.config

     文件       8477  2011-11-07 18:09  BWAcsBWAcs.csproj

     文件       4014  2011-11-10 15:27  BWAcsClass1.cs

     文件      59487  2011-12-06 12:41  BWAcsForm1.cs

     文件      88897  2011-11-10 23:12  BWAcsForm1.Designer.cs

     文件      28299  2011-11-10 23:12  BWAcsForm1.resx

     文件       1126  2011-11-09 01:11  BWAcsFormabout.cs

     文件       5980  2011-11-09 01:11  BWAcsFormabout.Designer.cs

     文件       8421  2011-11-09 01:11  BWAcsFormabout.resx

     文件        334  2011-10-08 19:29  BWAcsFormadd.cs

     文件       3044  2011-10-08 19:29  BWAcsFormadd.Designer.cs

     文件       5814  2011-10-08 19:29  BWAcsFormadd.resx

     文件       4287  2011-10-17 14:04  BWAcsformFind.cs

     文件       6958  2011-10-17 08:51  BWAcsformFind.Designer.cs

     文件       8226  2011-10-17 08:51  BWAcsformFind.resx

     文件       2518  2011-11-11 00:14  BWAcsFormGY.cs

     文件      13323  2011-11-11 00:14  BWAcsFormGY.Designer.cs

     文件       8420  2011-11-11 00:14  BWAcsFormGY.resx

     文件       6076  2011-10-17 16:30  BWAcsformReplace.cs

     文件       8988  2011-10-17 16:11  BWAcsformReplace.Designer.cs

     文件       8226  2011-10-17 16:11  BWAcsformReplace.resx

     文件        435  2012-02-08 23:15  BWAcsobjBWAcs.csproj.FileList.txt

     文件       2460  2011-11-11 00:14  BWAcsobjDebugBWAcs.csproj.GenerateResource.Cache

     文件     208896  2011-12-06 12:41  BWAcsobjDebugBWAcs.exe

     文件      14132  2011-11-10 23:12  BWAcsobjDebugBWAcs.Form1.resources

............此处省略111个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)