示例#1
0
        public static void DrawRtfText(this Graphics graphics, string text, string emphasis, Font f, Font bf, Rectangle layoutArea)
        {
            RichTextBoxDrawer rtfDrawer = new RichTextBoxDrawer();

            rtfDrawer.Multiline = true;

            if (Regex.IsMatch(text, emphasis, RegexOptions.IgnoreCase & RegexOptions.CultureInvariant))
            {
                text = Regex.Replace(text, emphasis, "%", RegexOptions.IgnoreCase & RegexOptions.CultureInvariant);
                var parts = text.Split('%');

                rtfDrawer.AppendText(parts[0], f);
                rtfDrawer.AppendText(emphasis, bf);
                rtfDrawer.AppendText(parts[1], f);
            }
            else
            {
                rtfDrawer.AppendText(text, f);
            }

            rtfDrawer.Draw(graphics, layoutArea);
        }
示例#2
0
        private static void AppendText(this RichTextBoxDrawer box, string text, Font font)
        {
            int ss = box.TextLength;

            box.AppendText(text);
            box.SelectionStart  = ss;
            box.SelectionLength = text.Length;
            box.SelectionFont   = font;
            if (!font.Bold)
            {
                box.SelectionColor = Color.DimGray;
            }
            else
            {
                box.SelectionColor = Color.Black;
            }
        }