示例#1
0
        private void HighlightLinks()
        {
            string textContent;

            this.Document.GetText(TextGetOptions.None, out textContent);
            int start = 0;
            int end   = textContent.Length;

            ITextRange range = this.Document.GetRange(start, end);

            range.CharacterFormat.Underline       = UnderlineType.None;
            range.CharacterFormat.ForegroundColor = this.textForegroundColor;

            if (this.Document.Selection == null)
            {
                return;
            }

            int startPosition = this.Document.Selection.StartPosition;
            int endPosition   = this.Document.Selection.EndPosition;

            foreach (string uri in RegexHelper.FindUris(textContent))
            {
                int result = range.FindText(uri, end - start, FindOptions.None);

                if (result > 0)
                {
                    this.Document.Selection.SetRange(range.StartPosition, range.EndPosition);
                    range.CharacterFormat.Underline       = UnderlineType.Single;
                    range.CharacterFormat.ForegroundColor = this.hyperlinkForegroundColor;

                    range.ScrollIntoView(PointOptions.None);
                }
            }

            this.Document.Selection.SetRange(startPosition, endPosition);
        }
示例#2
0
        public static void FastScrollToCaret(this TextBoxBase control)
        {
            if (control.IsHandleCreated)
            {
                var textLength = control.TextLength;

                if (textLength == 0)
                {
                    return;
                }
                bool   flag       = false;
                object iunknown   = null;
                var    iunkHandle = IntPtr.Zero;
                try
                {
                    if (SendMessage(new HandleRef(control, control.Handle), 1084, 0, out iunknown) != 0)
                    {
                        iunkHandle = Marshal.GetIUnknownForObject(iunknown);
                        if (iunkHandle != IntPtr.Zero)
                        {
                            var itextDocumentHandle = IntPtr.Zero;
                            var gUID = typeof(ITextDocument).GUID;
                            try
                            {
                                Marshal.QueryInterface(iunkHandle, ref gUID, out itextDocumentHandle);
                                var textDocument = Marshal.GetObjectForIUnknown(itextDocumentHandle) as ITextDocument;
                                if (textDocument != null)
                                {
                                    int        start             = control.SelectionStart;
                                    int        lineFromCharIndex = control.GetLineFromCharIndex(start);
                                    ITextRange textRange         = textDocument.Range(textLength - 1, textLength - 1);
                                    textRange.ScrollIntoView(0);
                                    int num3 = (int)Win32.SendMessage(control.Handle, (Win32.WM) 206, IntPtr.Zero, IntPtr.Zero);
                                    if (num3 > lineFromCharIndex)
                                    {
                                        textRange = textDocument.Range(start, start + control.SelectionLength);
                                        textRange.ScrollIntoView(32);
                                    }
                                    flag = true;
                                }
                            }
                            finally
                            {
                                if (itextDocumentHandle != IntPtr.Zero)
                                {
                                    Marshal.Release(itextDocumentHandle);
                                }
                            }
                        }
                    }
                }
                finally
                {
                    if (iunkHandle != IntPtr.Zero)
                    {
                        Marshal.Release(iunkHandle);
                    }
                }
                if (!flag)
                {
                    Win32.SendMessage(control.Handle, (Win32.WM) 183, IntPtr.Zero, IntPtr.Zero);
                    return;
                }
            }
            else
            {
                control.ScrollToCaret();
            }
        }