Esempio n. 1
0
        private void richEditControl1_DragOver(object sender, DragEventArgs e)
        {
            if (!customDragDropTarget)
            {
                return;
            }

            Point docPoint = Units.PixelsToDocuments(richEditControl1.PointToClient(Form.MousePosition),
                                                     richEditControl1.DpiX, richEditControl1.DpiY);

            DocumentPosition pos = richEditControl1.GetPositionFromPoint(docPoint);

            if (pos == null)
            {
                return;
            }

            Rectangle rect = Units.DocumentsToPixels(richEditControl1.GetBoundsFromPosition(pos),
                                                     richEditControl1.DpiX, richEditControl1.DpiY);

            richEditControl1.Document.CaretPosition = pos;

            if (richEditGraphics == null)
            {
                richEditGraphics = richEditControl1.CreateGraphics();
            }

            rect.Width = 2;
            richEditControl1.Refresh();
            richEditGraphics.FillRectangle(Brushes.Blue, rect);
            richEditControl1.ScrollToCaret();
        }
Esempio n. 2
0
        private void RichEditControl_ContentChanged(object sender, EventArgs e)
        {
            int    maxKeyLength = Math.Max(keyTextTable.Length, keyTextView.Length);
            string text         = Document.GetText(Document.CreateRange(Math.Max(0, Document.CaretPosition.ToInt() - maxKeyLength), maxKeyLength));

            if (text.EndsWith(keyTextTable) || text.EndsWith(keyTextView))
            {
                if (text.EndsWith(keyTextTable))
                {
                    userCommand = keyTextTable;
                }
                else if (text.EndsWith(keyTextView))
                {
                    userCommand = keyTextView;
                }
                else
                {
                    userCommand = string.Empty;
                }

                System.Drawing.Rectangle rect       = reEditor.GetBoundsFromPosition(Document.CaretPosition);
                System.Drawing.Rectangle localRect  = Units.DocumentsToPixels(rect, reEditor.DpiX, reEditor.DpiY);
                System.Drawing.Point     localPoint = new System.Drawing.Point(localRect.Right, localRect.Bottom);

                GeneralTransform generalTransform = this.TransformToVisual(reEditor);
                Point            point            = generalTransform.Transform(new Point(localPoint.X, localPoint.Y));
                reEditor.ShowMenu(point);
            }
        }
Esempio n. 3
0
        Point GetWindowLocation()
        {
            DocumentPosition position = this.richEdit.Document.CaretPosition;

            System.Drawing.Rectangle rect       = this.richEdit.GetBoundsFromPosition(position);
            System.Drawing.Point     location   = new System.Drawing.Point(rect.Right, rect.Bottom);
            System.Drawing.Point     localPoint = Units.DocumentsToPixels(location, this.richEdit.DpiX, this.richEdit.DpiY);
            return(new Point(localPoint.X, localPoint.Y));
        }
Esempio n. 4
0
        //This method places the form to the right of the cursor position:
        Point GetFormLocation()
        {
            DocumentPosition position   = this.richEditControl1.Document.CaretPosition;
            Rectangle        rect       = this.richEditControl1.GetBoundsFromPosition(position);
            Point            location   = new Point(rect.Right, rect.Bottom);
            Point            localPoint = Units.DocumentsToPixels(location, this.richEditControl1.DpiX, this.richEditControl1.DpiY);

            return(this.richEditControl1.PointToScreen(localPoint));
        }
Esempio n. 5
0
 void richEditControl1_MouseUp(object sender, MouseEventArgs e)
 {
     if (richEditControl1.Document.Selection.Length != 0)
     {
         DocumentPosition documentPosition  = richEditControl1.Document.CaretPosition;
         Rectangle        documentRectangle = richEditControl1.GetBoundsFromPosition(documentPosition);
         Point            documentPoint     = new Point(documentRectangle.Left, documentRectangle.Bottom);
         Point            clientPoint       = Units.DocumentsToPixels(documentPoint, richEditControl1.DpiX, richEditControl1.DpiY);
         Point            screenPoint       = richEditControl1.PointToScreen(clientPoint);
         ribbonMiniToolbar1.Show(screenPoint);
     }
 }
Esempio n. 6
0
        System.Windows.Point GetFormLocation()
        {
            //Retrive the caret position
            DocumentPosition position = this.richEditControl1.Document.CaretPosition;
            Rectangle        rect     = this.richEditControl1.GetBoundsFromPosition(position);

            //Set the startup location relative to the retrieved position
            //within the application bounds
            Rectangle richViewBounds = GetRichEditViewBounds();

            System.Drawing.Point location   = new System.Drawing.Point(rect.Right - richViewBounds.X, rect.Bottom - richViewBounds.Y);
            System.Drawing.Point localPoint = Units.DocumentsToPixels(location, this.richEditControl1.DpiX, this.richEditControl1.DpiY);
            return(new System.Windows.Point(localPoint.X, localPoint.Y));
        }
Esempio n. 7
0
        private void richEditControl1_Paint(object sender, PaintEventArgs e)
        {
            DocumentRange range = richEditControl1.Document.Selection;
            Rectangle     rect  = richEditControl1.GetBoundsFromPosition(range.Start);

            rect = new Rectangle(
                0,
                (int)Units.DocumentsToPixels(rect.Top, richEditControl1.DpiX),
                richEditControl1.ClientSize.Width,
                (int)Units.DocumentsToPixels(rect.Height, richEditControl1.DpiX));

            Brush brush = new SolidBrush(Color.FromArgb(100, Color.Red));

            e.Graphics.FillRectangle(brush, rect);
        }
Esempio n. 8
0
        private void richEditControl1_DragOver(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(typeof(GridCellData)))
            {
                return;
            }

            e.Effect = DragDropEffects.Move;

            Point docPoint = Units.PixelsToDocuments(richEditControl1.PointToClient(new Point(e.X, e.Y)),
                                                     richEditControl1.DpiX, richEditControl1.DpiY);

            DocumentPosition pos = richEditControl1.GetPositionFromPoint(docPoint);

            if (pos == null)
            {
                return;
            }

            Rectangle rect = Units.DocumentsToPixels(richEditControl1.GetBoundsFromPosition(pos),
                                                     richEditControl1.DpiX, richEditControl1.DpiY);

            richEditControl1.Document.CaretPosition = pos;

            if (richEditGraphics == null)
            {
                richEditGraphics = richEditControl1.CreateGraphics();
            }
            if (oldPosition != pos)
            {
                rect.Width = 2;
                richEditControl1.Refresh();
                richEditGraphics.FillRectangle(Brushes.Black, rect);
                richEditControl1.ScrollToCaret();
                oldPosition = pos;
            }
        }
Esempio n. 9
0
 public static System.Drawing.Rectangle GetRectangleFromDocumentPosition(RichEditControl richEditControl, DocumentPosition pos)
 {
     return(Units.DocumentsToPixels(richEditControl.GetBoundsFromPosition(pos),
                                    richEditControl.DpiX, richEditControl.DpiY));
 }