Example #1
0
        /// <summary>
        /// Calculate or render the contents of our RichTextBox for printing
        /// </summary>
        /// <param name="measureOnly">If true, only the calculation is performed,
        /// otherwise the text is rendered as well</param>
        /// <param name="b"></param>
        /// <param name="rtb"></param>
        /// <param name="charFrom">Index of first character to be printed</param>
        /// <param name="charTo">Index of last character to be printed</param>
        /// <returns>(Index of last character that fitted on the
        /// page) + 1</returns>
        //public int FormatRange(bool measureOnly, PrintPageEventArgs e, int charFrom, int charTo)
        public int FormatRange(bool measureOnly, DevAge.Windows.Forms.DevAgeRichTextBox rtb,
                               ref Bitmap b, int charFrom, int charTo)
        {
            // Specify which characters to print
            STRUCT_CHARRANGE cr;

            cr.cpMin = charFrom;
            cr.cpMax = charTo;

            // Specify the area inside page margins
            STRUCT_RECT rc;

            rc.Top    = HundredthInchToTwips(0);
            rc.Bottom = HundredthInchToTwips(b.Height);
            rc.Left   = HundredthInchToTwips(0);
            rc.Right  = HundredthInchToTwips(b.Width);

            // Specify the page area
            STRUCT_RECT rcPage;

            rcPage.Top    = HundredthInchToTwips(0);
            rcPage.Bottom = HundredthInchToTwips(b.Height);
            rcPage.Left   = HundredthInchToTwips(0);
            rcPage.Right  = HundredthInchToTwips(b.Width);

            // Get device context of output device
            Graphics g   = Graphics.FromImage(b);
            IntPtr   hdc = g.GetHdc();

            // Fill in the FORMATRANGE struct
            STRUCT_FORMATRANGE fr;

            fr.chrg      = cr;
            fr.hdc       = hdc;
            fr.hdcTarget = hdc;
            fr.rc        = rc;
            fr.rcPage    = rcPage;

            // Non-Zero wParam means render, Zero means measure
            Int32 wParam = (measureOnly ? 0 : 1);

            // Allocate memory for the FORMATRANGE struct and
            // copy the contents of our struct to this memory
            IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fr));

            Marshal.StructureToPtr(fr, lParam, false);

            // Send the actual Win32 message
            int res = SendMessage(rtb.Handle, EM_FORMATRANGE, wParam, lParam);

            // Free allocated memory
            Marshal.FreeCoTaskMem(lParam);

            // and release the device context
            g.ReleaseHdc(hdc);

            g.Dispose();

            return(res);
        }
Example #2
0
 /// <summary>
 /// Create the editor control
 /// </summary>
 /// <returns></returns>
 protected override Control CreateControl()
 {
     DevAge.Windows.Forms.DevAgeRichTextBox editor = new DevAge.Windows.Forms.DevAgeRichTextBox();
     editor.BorderStyle = BorderStyle.None;
     editor.AutoSize    = false;
     editor.Validator   = this;
     return(editor);
 }
Example #3
0
 /// <summary>
 /// Create the editor control
 /// </summary>
 /// <returns></returns>
 protected override Control CreateControl()
 {
     DevAge.Windows.Forms.DevAgeRichTextBox editor = new DevAge.Windows.Forms.DevAgeRichTextBox();
     editor.BorderStyle = BorderStyle.None;
     editor.AutoSize = false;
     editor.Validator = this;
     return editor;
 }
Example #4
0
        /// <summary>
        /// This method is called just before the edit start.
        /// You can use this method to customize the editor with the cell informations.
        /// </summary>
        /// <param name="cellContext"></param>
        /// <param name="editorControl"></param>
        protected override void OnStartingEdit(CellContext cellContext, Control editorControl)
        {
            base.OnStartingEdit(cellContext, editorControl);

            DevAge.Windows.Forms.DevAgeRichTextBox l_RchTxtBox = (DevAge.Windows.Forms.DevAgeRichTextBox)editorControl;
            l_RchTxtBox.WordWrap = cellContext.Cell.View.WordWrap;

            // to set the scroll of the textbox to the initial position
            //(otherwise the richtextbox uses the previous scroll position)
            l_RchTxtBox.SelectionStart  = 0;
            l_RchTxtBox.SelectionLength = 0;
        }
        /// <summary>
        /// If ValueEventArgs is a font, use it to change SelectionFont
        /// If String, assign it as rtf
        /// If Int32, assign it as offset
        /// If HorizontalAlignment, assign as SelectionAlignment
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnValueChanging(CellContext sender, ValueChangeEventArgs e)
        {
            base.OnValueChanging(sender, e);

            // only check if event args is of known type if event is not of type rich text
            if (!(e.NewValue is DevAge.Windows.Forms.RichText))
            {
                Editors.RichTextBox richEditor = (Editors.RichTextBox)sender.Cell.Editor;
                DevAge.Windows.Forms.DevAgeRichTextBox richTextBox = richEditor.Control;

                // if editor is not open, assign value and select all text
                if (sender.Cell.Editor.EditCell == null)
                {
                    richTextBox.Value = sender.Value as DevAge.Windows.Forms.RichText;
                    richTextBox.SelectAll();
                }

                if (e.NewValue is Font)
                {
                    richTextBox.SelectionFont = (Font)e.NewValue;
                }
                else if (e.NewValue is Color)
                {
                    richTextBox.SelectionColor = (Color)e.NewValue;
                }
                else if (e.NewValue is Int32)
                {
                    richTextBox.SelectionCharOffset = (int)e.NewValue;
                }
                else if (e.NewValue is HorizontalAlignment)
                {
                    richTextBox.SelectionAlignment = (HorizontalAlignment)e.NewValue;
                }
                else if (e.NewValue is DevAge.Windows.Forms.EffectType)
                {
                    richTextBox.SelectionEffect = (DevAge.Windows.Forms.EffectType)e.NewValue;
                }

                // if editor is not open, use changed value for cell
                if (sender.Cell.Editor.EditCell == null)
                {
                    sender.Value = richTextBox.Value;
                }
            }
        }
Example #6
0
        /// <summary>
        /// This method is called just before the edit start.
        /// You can use this method to customize the editor with the cell informations.
        /// </summary>
        /// <param name="cellContext"></param>
        /// <param name="editorControl"></param>
        protected override void OnStartingEdit(CellContext cellContext, Control editorControl)
        {
            base.OnStartingEdit(cellContext, editorControl);

            DevAge.Windows.Forms.DevAgeRichTextBox l_RchTxtBox = editorControl as DevAge.Windows.Forms.DevAgeRichTextBox;

            //[email protected]: check if control exists
            if (l_RchTxtBox == null)
            {
                return;
            }

            l_RchTxtBox.WordWrap = cellContext.Cell.View.WordWrap;

            // to set the scroll of the textbox to the initial position
            //(otherwise the richtextbox uses the previous scroll position)
            l_RchTxtBox.SelectionStart  = 0;
            l_RchTxtBox.SelectionLength = 0;
        }
Example #7
0
        /// <summary>
        /// Free cached data from rich edit control after printing
        /// </summary>
        public void FormatRangeDone(DevAge.Windows.Forms.DevAgeRichTextBox RTB)
        {
            IntPtr lParam = new IntPtr(0);

            SendMessage(RTB.Handle, EM_FORMATRANGE, 0, lParam);
        }