示例#1
0
        private void OpenButton_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "rtf files|*.rtf";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                TextRichTextBox.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.RichText);
            }
        }
示例#2
0
 private void SaveButton_Click(object sender, EventArgs e)
 {
     try
     {
         TextRichTextBox.SaveFile(@"../../Test.rtf", RichTextBoxStreamType.RichText);
         MessageBox.Show("The file has been saved!");
     }
     catch (FileNotFoundException fnfe)
     {
         MessageBox.Show(fnfe.Message);
     }
 }
示例#3
0
 private void LoadButton_Click(object sender, EventArgs e)
 {
     try
     {
         TextRichTextBox.LoadFile(@"../../Test.rtf");
         MessageBox.Show("The file has been loaded!");
     }
     catch (FileNotFoundException)
     {
         MessageBox.Show("File has not been saved yet!");
     }
 }
示例#4
0
        private void CenterButton_Click(object sender, EventArgs e)
        {
            if (TextRichTextBox.SelectionAlignment == HorizontalAlignment.Center)
            {
                TextRichTextBox.SelectionAlignment = HorizontalAlignment.Left;
            }
            else
            {
                TextRichTextBox.SelectionAlignment = HorizontalAlignment.Center;
            }

            TextRichTextBox.Focus();
        }
示例#5
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "rtf files|*.rtf";

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if (TextRichTextBox.Text != "")
                {
                    TextRichTextBox.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.RichText);
                    TextRichTextBox.Clear();
                    MessageBox.Show("Text has been saved!");
                }
            }
        }
示例#6
0
        private void SizeTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < 45 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != 13)
            {
                e.Handled = true;
            }

            else if (e.KeyChar == 13)
            {
                TextBox txt = (TextBox)sender;

                if (txt.Text.Length > 0)
                {
                    ChangeFontSize(txt.Text);
                }

                e.Handled = true;
                TextRichTextBox.Focus();
            }
        }
示例#7
0
        private void UnderlineButton_Click(object sender, EventArgs e)
        {
            Font newFont;
            Font oldFont;

            oldFont = TextRichTextBox.SelectionFont;

            if (oldFont.Underline)
            {
                newFont = new Font(oldFont, oldFont.Style & ~FontStyle.Underline);
            }
            else
            {
                newFont = new Font(oldFont, oldFont.Style | FontStyle.Underline);
            }

            //setting new font and focus on text area
            TextRichTextBox.SelectionFont = newFont;
            TextRichTextBox.Focus();
        }
        private void UpdateTextRichTextBox(int currentLine = -1)
        {
            FlowDocument doc = new FlowDocument( );
            double       pos = TextRichTextBox.VerticalOffset;

            foreach (var line in _displayInfo.TextOutput.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var newparag = new Paragraph( );
                if (doc.Blocks.Count + 1 == currentLine)
                {
                    var span = new Span( );
                    span.Inlines.Add(new Run(line));
                    span.Background = new SolidColorBrush(Colors.LightBlue);
                    newparag.Inlines.Add(span);
                }
                else
                {
                    newparag.Inlines.Add(new Run(line));
                }
                doc.Blocks.Add(newparag);
            }
            TextRichTextBox.Document = doc;
            TextRichTextBox.ScrollToVerticalOffset(pos);
        }