Exemple #1
0
        private string CharRangeToString(CHARRANGE c)
        {
            var lParam = new TEXTRANGE();

            lParam.chrg = c;
            //if ((c.cpMax > this.Text.Length) || ((c.cpMax - c.cpMin) <= 0))
            //{
            //    return string.Empty;
            //}
            int        size   = (c.cpMax - c.cpMin) + 1;
            CharBuffer buffer = CharBuffer.CreateBuffer(size);
            IntPtr     ptr    = buffer.AllocCoTaskMem();

            if (ptr == IntPtr.Zero)
            {
                throw new OutOfMemoryException("OutOfMemory");
            }
            lParam.lpstrText = ptr;
            var num1 = (int)SendMessage(new HandleRef(this, base.Handle), 0x44b, 0, lParam);

            buffer.PutCoTaskMem(ptr);
            if (lParam.lpstrText != IntPtr.Zero)
            {
                Marshal.FreeCoTaskMem(ptr);
            }
            return(buffer.GetString());
        }
Exemple #2
0
            public static CHARRANGE FromManaged(CharacterRange input)
            {
                CHARRANGE result = new CHARRANGE();

                result.cpMin = input.First;
                result.cpMax = input.First + input.Length;
                return(result);
            }
        /// <summary>Prints the specified character from.</summary>
        /// <param name="charFrom">The character from.</param>
        /// <param name="charTo">The character to.</param>
        /// <param name="e">The <see cref="PrintPageEventArgs"/> instance containing the event data.</param>
        /// <returns></returns>
        public int Print(int charFrom, int charTo, PrintPageEventArgs e)
        {
            CHARRANGE cHARRANGE = new CHARRANGE();

            FORMATRANGE fORMATRANGE = new FORMATRANGE();

            RECT rECT = new RECT(), rECT1 = new RECT();

            cHARRANGE.cpMin = charFrom;

            cHARRANGE.cpMax = charTo;

            Rectangle marginBounds = e.MarginBounds;

            rECT1.Top = checked ((int)Math.Round((double)marginBounds.Top * 14.4));

            marginBounds = e.MarginBounds;

            rECT1.Bottom = checked ((int)Math.Round((double)marginBounds.Bottom * 14.4));

            marginBounds = e.MarginBounds;

            rECT1.Left = checked ((int)Math.Round((double)marginBounds.Left * 14.4));

            marginBounds = e.MarginBounds;

            rECT1.Right = checked ((int)Math.Round((double)marginBounds.Right * 14.4));

            marginBounds = e.PageBounds;

            rECT.Top = checked ((int)Math.Round((double)marginBounds.Top * 14.4));

            marginBounds = e.PageBounds;

            rECT.Bottom = checked ((int)Math.Round((double)marginBounds.Bottom * 14.4));

            marginBounds = e.PageBounds;

            rECT.Left = checked ((int)Math.Round((double)marginBounds.Left * 14.4));

            marginBounds = e.PageBounds;

            rECT.Right = checked ((int)Math.Round((double)marginBounds.Right * 14.4));

            IntPtr hdc             = e.Graphics.GetHdc();

            fORMATRANGE.chrg = cHARRANGE;

            fORMATRANGE.hdc = hdc;

            fORMATRANGE.hdcTarget = hdc;

            fORMATRANGE.rc = rECT1;

            fORMATRANGE.rcPage = rECT;

            IntPtr zero = IntPtr.Zero, intPtr = IntPtr.Zero;

            intPtr = new IntPtr(1);

            IntPtr zero1 = IntPtr.Zero;

            zero1 = Marshal.AllocCoTaskMem(Marshal.SizeOf <FORMATRANGE>(fORMATRANGE));

            Marshal.StructureToPtr <FORMATRANGE>(fORMATRANGE, zero1, false);

            zero = SendMessage(Handle, 1081, intPtr, zero1);

            Marshal.FreeCoTaskMem(zero1);

            e.Graphics.ReleaseHdc(hdc);

            return(zero.ToInt32());
        }
Exemple #4
0
 internal static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref CHARRANGE range);
Exemple #5
0
 public static CharacterRange ToManaged(CHARRANGE input)
 {
     return(new CharacterRange(input.cpMin, input.cpMax - input.cpMin));
 }
            public string    text;          // Allocated by caller, zero terminated by RichEdit

            public TEXTRANGE(int min, int max)
            {
                char_range = new CHARRANGE(min, max);
                text       = new string('\0', max - min);
            }
Exemple #7
0
 private string CharRangeToString(CHARRANGE c)
 {
     var lParam = new TEXTRANGE();
     lParam.chrg = c;
     //if ((c.cpMax > this.Text.Length) || ((c.cpMax - c.cpMin) <= 0))
     //{
     //    return string.Empty;
     //}
     int size = (c.cpMax - c.cpMin) + 1;
     CharBuffer buffer = CharBuffer.CreateBuffer(size);
     IntPtr ptr = buffer.AllocCoTaskMem();
     if (ptr == IntPtr.Zero)
     {
         throw new OutOfMemoryException("OutOfMemory");
     }
     lParam.lpstrText = ptr;
     var num1 = (int) SendMessage(new HandleRef(this, base.Handle), 0x44b, 0, lParam);
     buffer.PutCoTaskMem(ptr);
     if (lParam.lpstrText != IntPtr.Zero)
     {
         Marshal.FreeCoTaskMem(ptr);
     }
     return buffer.GetString();
 }
Exemple #8
0
 private static extern void RichTextBox_CharRange(out CHARRANGE value);