private void OnMouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Control)
            {
                if (e.Delta > 0 && lstOutputMessages.FontSize < 24)
                {
                    lstOutputMessages.FontSize = lstOutputMessages.FontSize + 1;
                    ITextEditorSettings settings = TextEditorControl.Instance.TextCore.TextEditorSettings;
                    settings.FontMultiplier = settings.FontMultiplier + 1;
                }
                else if (e.Delta < 0 && lstOutputMessages.FontSize > 12)
                {
                    lstOutputMessages.FontSize = lstOutputMessages.FontSize - 1;
                    ITextEditorSettings settings = TextEditorControl.Instance.TextCore.TextEditorSettings;
                    settings.FontMultiplier = settings.FontMultiplier + 1;
                }

                e.Handled = true;
            }
            else
            {
                if (e.Delta > 0 && offset < outputWindow.Height)
                {
                    OutputScrollViewer.ScrollToVerticalOffset(offset);
                }
                else if (e.Delta < 0 && offset > 0)
                {
                    OutputScrollViewer.ScrollToVerticalOffset(offset--);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// If scroll viewer is already scrolled all the way down, scroll to
        /// bottom after printing new line of content.
        /// Otherwise, if scroll viewer is scrolled up more than 1 pixel above
        /// the bottom of the scrollable content, do not scroll.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            bool scrollBarAtBottom = OutputScrollViewer.VerticalOffset == (OutputScrollViewer.ExtentHeight - OutputScrollViewer.ViewportHeight);

            if (scrollBarAtBottom)
            {
                OutputScrollViewer.ScrollToBottom();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// If scroll viewer is already scrolled all the way down, scroll to
        /// bottom after printing new line of content.
        /// Otherwise, if scroll viewer is scrolled up more than 1 pixel above
        /// the bottom of the scrollable content, do not scroll.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            var offset = OutputScrollViewer.VerticalOffset;

            if (offset == (OutputScrollViewer.ExtentHeight - OutputScrollViewer.ViewportHeight))
            {
                OutputScrollViewer.ScrollToBottom();
            }
        }
Esempio n. 4
0
 private void Log(string message)
 {
     Dispatcher.BeginInvoke(() =>
     {
         Debug.WriteLine(message);
         OutputTextBox.Text += "\n" + message;
         // Scroll to bottom
         OutputScrollViewer.UpdateLayout();
         OutputScrollViewer.ScrollToVerticalOffset(OutputScrollViewer.ScrollableHeight);
     });
 }
Esempio n. 5
0
        private void ShowString(string msg)
        {
            //OutputTextBlock.Text += "\r\n" + msg;

            TextBlock lastText = new TextBlock()
            {
                Text = msg, TextWrapping = TextWrapping.Wrap
            };

            lastText.FontSize = 25;
            OutputStack.Children.Add(lastText);

            //Scroll to end
            this.Dispatcher.BeginInvoke(() =>
            {
                OutputScrollViewer.ScrollToVerticalOffset(OutputScrollViewer.ScrollableHeight);
            });
        }
Esempio n. 6
0
        public MainWindow()
        {
            InitializeComponent();

            OutputScrollViewer.ScrollToEnd();

            monitor  = new Monitor(Output);
            canStart = !monitor.IsRunning;

            monitor.StartRunning += delegate
            {
                canStart = false;
                Application.Current.Dispatcher.Invoke(new Action(() => ToggleMonitor.Content = "Stop"));
            };

            monitor.StopRunning += delegate
            {
                canStart = true;
                Application.Current.Dispatcher.Invoke(new Action(() => ToggleMonitor.Content = "Start"));
            };
        }
        private void OutputStatusMessage(String msg)
        {
            var splits = msg.Split('\n');

            foreach (var split in splits)
            {
                var trimmed = split.Trim('\r');

                // Remember that SendStatusMessage is called from ReceiveMessage, which is assigned to a delegate of the example base class.
                // Since the example base class is executed outside of the main thread i.e. RunAsync, you must check to make sure this thread
                // has access to components of the application window i.e. OutputScrollViewer.
                if (!Dispatcher.CheckAccess())
                {
                    Dispatcher.Invoke(new SendStatusMessageDelegate(OutputStatusMessage), msg);
                    return;
                }

                OutputScrollViewer.Content += (trimmed + "\r\n");
                OutputScrollViewer.ScrollToBottom();
            }
        }
Esempio n. 8
0
 private void SetupAutoScroll()
 {
     DependencyPropertyDescriptor
     .FromProperty(TextBlock.TextProperty, typeof(TextBlock))
     .AddValueChanged(OutputTextBlock, (sender, args) => OutputScrollViewer.ScrollToEnd());
 }
 private void OnOutputChanged(object sender, DataTransferEventArgs e)
 {
     OutputScrollViewer.ScrollToEnd();
 }
Esempio n. 10
0
        public void WriteData(string data)
        {
            //Paragraph paragraph = new Paragraph();
            //paragraph.Inlines.Add(data);
            //OutputRichTextBox.Document.Blocks.Add(paragraph);

            data = DateTime.Now.ToString("HH:mm:ss.ffffff") + data;

            Debug.WriteLine($"DATA:[{data}]");

            Dispatcher.InvokeAsync(() =>
            {
                Paragraph paragraph = new Paragraph();

                // Parse color code
                Brush currentColor = Brushes.LightGray;
                string remaining   = data;
                while (true)
                {
                    int startIndex = remaining.IndexOf("%", StringComparison.OrdinalIgnoreCase);
                    //Debug.WriteLine($"StartIndex:[{startIndex}]");
                    if (startIndex >= 0)
                    {
                        string preceding = remaining.Substring(0, startIndex);
                        remaining        = remaining.Substring(startIndex + 1);
                        //Debug.WriteLine($"Preceding:[{preceding}]");
                        //Debug.WriteLine($"Remaining:[{remaining}]");
                        AddColoredTextToParagraph(paragraph, currentColor, preceding);
                        //Debug.WriteLine($"AddColoredTextToParagraph preceding:[{preceding}] {currentColor}");
                        int endIndex = remaining.IndexOf("%", StringComparison.OrdinalIgnoreCase);
                        //Debug.WriteLine($"EndIndex:[{endIndex}]");
                        if (endIndex == 1) // %c%
                        {
                            string colorCode = remaining.Substring(0, endIndex);
                            //Debug.WriteLine($"ColorCode:[{colorCode}]");
                            Brush newColor = GetColor(colorCode);
                            if (newColor != null)
                            {
                                currentColor = newColor;
                                remaining    = remaining.Substring(endIndex + 1);
                            }
                            else
                            {
                                //Debug.WriteLine($"AddColoredTextToParagraph % not color:[%] {currentColor}");
                                AddColoredTextToParagraph(paragraph, currentColor, "%");
                            }
                        }
                        else
                        {
                            //Debug.WriteLine($"AddColoredTextToParagraph %:[%] {currentColor}");
                            AddColoredTextToParagraph(paragraph, currentColor, "%");
                        }
                    }
                    else
                    {
                        //Debug.WriteLine($"AddColoredTextToParagraph remaining:[{remaining}] {currentColor}");
                        AddColoredTextToParagraph(paragraph, currentColor, remaining);
                        break;
                    }
                }
                OutputRichTextBox.Document.Blocks.Add(paragraph);
                OutputScrollViewer.ScrollToBottom();
            });
        }
Esempio n. 11
0
 private void ToggleButton_Click(object sender, RoutedEventArgs e)
 {
     OutputScrollViewer.ScrollToBottom();
 }
Esempio n. 12
0
 private void AppendRichText(string message)
 {
     OutputRichTextBox.AppendText(String.Format("<{0:yyyy/MM/dd HH:mm:ss}>\n", DateTime.Now));
     OutputRichTextBox.AppendText(message);
     OutputScrollViewer.ScrollToEnd();
 }