ScrollToVerticalOffset() public method

Scrolls to the specified position in the document.
public ScrollToVerticalOffset ( double offset ) : void
offset double
return void
Exemplo n.º 1
0
        //...........................................................

        protected void ScrollBarVChanged(object SENDER, System.Windows.RoutedPropertyChangedEventArgs <double> ARGS)
        {
            var sender = SENDER as ScrollBar;
            var offset = sender.Value;

            m_viewerL.ScrollToVerticalOffset(offset);
            m_viewerR.ScrollToVerticalOffset(offset);
        }
Exemplo n.º 2
0
        //public void ClearLabels()
        //{
        //    var ruleset = editor.SyntaxHighlighting.GetNamedRuleSet("LabelsRuleSet");
        //    ruleset.Rules.Clear();
        //}

        //public void AddLabel(string name)
        //{
        //    var color = editor.SyntaxHighlighting.GetNamedColor("Label");
        //    var ruleset = editor.SyntaxHighlighting.GetNamedRuleSet("LabelsRuleSet");
        //    ruleset.Rules.Add(new HighlightingRule() {
        //        Color = color,
        //        Regex = new Regex($"\\b(?>{Regex.Escape(name)})\\b",
        //            RegexOptions.ExplicitCapture | RegexOptions.CultureInvariant)
        //    });
        //}

        public void SelectLine(int lineNumber)
        {
            // https://geek-questions.github.io/articles/1340178/index.html

            //Get the line number based off the offset.
            var line = editor.Document.GetLineByNumber(lineNumber);

            //Select the text.
            editor.Select(line.Offset, line.Length);
            //Scroll the textEditor to the selected line.
            var visualTop = editor.TextArea.TextView.GetVisualTopByDocumentLine(lineNumber);

            editor.ScrollToVerticalOffset(visualTop);
        }
Exemplo n.º 3
0
 public void ScrollToVerticalOffset(double offset)
 {
     _editor.ScrollToVerticalOffset(offset);
 }
Exemplo n.º 4
0
        //Add document
        private TextEditor AddDocument(string hLight, string title = null, bool showInRight = false, TextEditor syncBox = null)
        {
            //Define objects
            FoldingManager foldingManager;
            LayoutDocument dc = new LayoutDocument();
            Grid gd = new Grid();
            TextEditor rtb = new TextEditor();
            TextBox tb = new TextBox();

            //Installs the folding manager
            foldingManager = FoldingManager.Install(rtb.TextArea);

            //Get title
            if (title == null)
                title = "New page";

            //Check for multiple titles
            int counter = 0;
            foreach (LayoutDocument ld in documentPanel.Children) {
                if (ld.Title.Contains(title))
                    counter++;
            }

            //Object properties
            if (counter > 0)
                dc.Title = title + " (" + counter + ")";
            else
                dc.Title = title;
            tb.Margin = new Thickness(0,0,0,0);
            tb.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            tb.VerticalContentAlignment = System.Windows.VerticalAlignment.Center;
            tb.BorderBrush = new SolidColorBrush(Color.FromRgb(226,226,226));
            tb.Foreground = new SolidColorBrush(Color.FromRgb(91, 91, 91));
            tb.SelectionBrush = new SolidColorBrush(Color.FromArgb(90, 0, 0, 0));
            tb.Height = 23;

            //Text editor area
            rtb.AllowDrop = true;
            rtb.Tag = foldingManager;
            rtb.Margin = new Thickness(0, 23, 0, 0);
            rtb.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            rtb.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            rtb.FontFamily = new System.Windows.Media.FontFamily("Courier New");
            rtb.FontSize = Convert.ToDouble(12);
            rtb.Padding = new Thickness(11);
            rtb.ShowLineNumbers = true;
            rtb.LineNumbersForeground = new SolidColorBrush(Color.FromRgb(140, 140, 140));
            rtb.TextArea.Options.EnableEmailHyperlinks = true;
            rtb.TextArea.Options.EnableHyperlinks = true;
            rtb.TextArea.Options.EnableTextDragDrop = true;
            rtb.TextArea.SelectionCornerRadius = 0;
            rtb.TextArea.SelectionBrush = new SolidColorBrush(Color.FromArgb(190, 0, 0, 0));
            rtb.TextArea.SelectionBorder = new Pen(new SolidColorBrush(Color.FromArgb(30, 0, 0, 0)), 1);
            //rtb.TextArea.TextView.LineTransformers.Add(new ColorizeAvalonEdit());
            rtb.Options.EnableRectangularSelection = true;
            rtb.Options.AllowScrollBelowDocument = true;

            //Rich text change
            rtb.TextChanged += new EventHandler(
                delegate(object sender, EventArgs e)
                {
                    //Update folding layout
                    try
                    {
                        //Set status to not saved
                        if (!activeLayout().Title.EndsWith(" *"))
                            activeLayout().Title += " *";

                        //Update stats
                        documentStats();
                        foldingStrategy.UpdateFoldings((activeDocument().Tag as FoldingManager), activeDocument().Document);
                    }
                    catch { }
                });
            rtb.TextArea.Caret.PositionChanged += new EventHandler(
                delegate(object sender, EventArgs e) {
                    try {
                        documentStats();
                    }
                    catch { }
                });
            if (showInRight && syncBox != null) {
                //rtb.TextArea.TextView.ScrollOffsetChanged += new EventHandler(
                //	delegate(object sender, EventArgs e) {
                //		if (IsMouseOver)
                //			syncBox.ScrollToVerticalOffset(rtb.VerticalOffset);

                //});
                syncBox.TextArea.Caret.PositionChanged += new EventHandler(
                    delegate(object sender, EventArgs e) {
                        rtb.ScrollToVerticalOffset(syncBox.VerticalOffset);
                });
                syncBox.TextArea.TextView.ScrollOffsetChanged += new EventHandler(
                    delegate(object sender, EventArgs e) {
                        if (IsMouseOver)
                            rtb.ScrollToVerticalOffset(syncBox.VerticalOffset);
                });
            }
            dc.IsSelectedChanged += new EventHandler(
                delegate(object sender, EventArgs e)
                {
                    //Update folding layout
                    try
                    {
                        documentStats();
                        ApplyFoldings(activeDocument());
                        //foldingStrategy.UpdateFoldings((activeDocument().Tag as FoldingManager), activeDocument().Document);
                    }
                    catch { }
                });

            //Add document
            dc.Content = gd;
            if (showInRight) {
                documentPanelRight.Children.Add(dc);
                rtb.IsReadOnly = true;
                ApplyFoldings(rtb);
            }
            else
                documentPanel.Children.Add(dc);
            dc.IsSelected = true;
            dc.IsActive = true;

            //Add children structure
            gd.Children.Add(rtb);
            gd.Children.Add(tb);

            //Apply default highlight
            ApplyHighlight(rtb, hLight);

            //Return the box
            return rtb;
        }