private int Print(RichTextBox box, int charFrom, int charTo, PrintPageEventArgs e)
        {
            RichTextBoxPrint.RECT rc;
            rc.Top    = (int)((double)e.MarginBounds.Top * 14.4);
            rc.Bottom = (int)((double)e.MarginBounds.Bottom * 14.4);
            rc.Left   = (int)((double)e.MarginBounds.Left * 14.4);
            rc.Right  = (int)((double)e.MarginBounds.Right * 14.4);
            RichTextBoxPrint.RECT rcPage;
            rcPage.Top    = (int)((double)e.PageBounds.Top * 14.4);
            rcPage.Bottom = (int)((double)e.PageBounds.Bottom * 14.4);
            rcPage.Left   = (int)((double)e.PageBounds.Left * 14.4);
            rcPage.Right  = (int)((double)e.PageBounds.Right * 14.4);
            IntPtr hdc = e.Graphics.GetHdc();

            RichTextBoxPrint.FORMATRANGE fORMATRANGE;
            fORMATRANGE.chrg.cpMax = charTo;
            fORMATRANGE.chrg.cpMin = charFrom;
            fORMATRANGE.hdc        = hdc;
            fORMATRANGE.hdcTarget  = hdc;
            fORMATRANGE.rc         = rc;
            fORMATRANGE.rcPage     = rcPage;
            IntPtr intPtr = IntPtr.Zero;
            IntPtr zero   = IntPtr.Zero;

            zero = new IntPtr(1);
            IntPtr intPtr2 = IntPtr.Zero;

            intPtr2 = Marshal.AllocCoTaskMem(Marshal.SizeOf(fORMATRANGE));
            Marshal.StructureToPtr(fORMATRANGE, intPtr2, false);
            intPtr = RichTextBoxPrint.SendMessage(box.Handle, 1081, zero, intPtr2);
            Marshal.FreeCoTaskMem(intPtr2);
            e.Graphics.ReleaseHdc(hdc);
            return(intPtr.ToInt32());
        }
        public bool ProcessCMD(string cmd)
        {
            bool flag = cmd == "DoPrint";

            if (flag)
            {
                RichTextBoxPrint richTextBoxPrint = new RichTextBoxPrint();
                richTextBoxPrint.DoPrint(this.richTextBox1);
            }
            return(true);
        }