Ejemplo n.º 1
0
        private void AddTextToRichTextBox(RichTextBox rtb, bool bold, bool italic, bool underline, string color, string text)
        {
            if (text.Length > 0)
            {
                int length = rtb.Text.Length;
                richTextBoxPreview.Text += text;
                _colorList.Add(new ColorEntry {
                    Start = length, Length = text.Length, Color = HtmlUtil.GetColorFromString(color)
                });

                var fontStyle = new FontStyle();
                if (underline)
                {
                    fontStyle = FontStyle.Underline;
                }

                if (italic)
                {
                    fontStyle |= FontStyle.Italic;
                }

                if (bold)
                {
                    fontStyle |= FontStyle.Bold;
                }

                _fontList.Add(new FontEntry {
                    Start = length, Length = text.Length, Font = new Font(rtb.Font.FontFamily, rtb.Font.Size, fontStyle)
                });
            }
        }
Ejemplo n.º 2
0
        private void AddTextToRichTextBox(RichTextBox rtb, bool bold, bool italic, bool underline, string color, string text)
        {
            if (text.Length <= 0)
            {
                return;
            }

            var length = rtb.Text.Length;

            richTextBoxPreview.Text += text;

            var c = Color.White;

            if (!string.IsNullOrWhiteSpace(color))
            {
                c = HtmlUtil.GetColorFromString(color);
            }

            _colorList.Add(new ColorEntry {
                Start = length, Length = text.Length, Color = c
            });

            var fontStyle = new FontStyle();

            if (underline)
            {
                fontStyle |= FontStyle.Underline;
            }

            if (italic)
            {
                fontStyle |= FontStyle.Italic;
            }

            if (bold)
            {
                fontStyle |= FontStyle.Bold;
            }

            _fontList.Add(new FontEntry {
                Start = length, Length = text.Length, Font = new Font(rtb.Font.FontFamily, rtb.Font.Size, fontStyle)
            });
        }