public TextLogLineEventArgs(RichText line) { TextLogLine = line; }
public static RichText ParseText(string s, Color?generalColor = null, Font generalFont = null, List <RichTextParseRule> rules = null) { if (generalColor == null) { generalColor = Color.White; } if (generalFont == null) { generalFont = Control.DefaultFont; } if (rules == null) { rules = RichTextRules; } if (rules == null) { return(s.ToRichText(generalColor, generalFont)); } RichText richText = new RichText(); richText._text = s; string[] rawParts = s.Split('$', '<'); List <string> finalParts = new List <string>(); foreach (string part in rawParts) { if (part.Length < 1) { continue; } if (part[0] == '(') { // (key) StringBuilder sb = new StringBuilder(); int index = 0; while (part[index] != ')') { sb.Append(part[index++]); } // $key finalParts.Add('$' + sb.ToString().Substring(1)); finalParts.Add(part.Substring(index + 1)); } else if (part[0] == '[') { // [r,b,g]> // [r,b,g] int endIndex = part.IndexOf('>'); finalParts.Add(part.Substring(0, endIndex)); finalParts.Add(part.Substring(endIndex + 1, part.Length - endIndex - 1)); } else { finalParts.Add(part); } } foreach (string part in finalParts) { if (part.Length < 1) { continue; } if (part[0] == '$') { foreach (RichTextParseRule rule in rules) { if (part.Substring(1) == rule.Key) { richText.Sections.Add(new RichTextSection(rule.Value, rule.Color, rule.Font)); } } } else if (part[0] == '[') { // <[255,255,255]This is coloured text!> string sr = ""; int index = 1; while (part[index] != ',') { sr += part[index++]; } int r = Convert.ToInt32(sr); string sb = ""; index++; while (part[index] != ',') { sb += part[index++]; } int b = Convert.ToInt32(sb); string sg = ""; index++; while (part[index] != ']') { sg += part[index++]; } int g = Convert.ToInt32(sg); richText.Sections.Add(new RichTextSection(part.Substring(index + 1), new Color(r, b, g), generalFont)); } else { richText.Sections.Add(new RichTextSection(part, generalColor, generalFont)); } } return(richText); }
/// <summary> /// Initializes a new instance of the Label class with default settings and optional parent /// </summary> /// <param name="pos">Position of the Label</param> /// <param name="text">Text to be drawn</param> /// <param name="parent">Optional parent</param> public Label(Rectangle pos, RichText text, Control parent = null) : base(pos, parent) { TextChanged += Label_TextChanged; Text = text; }
public static RichText ToRichText(this string s, Color?color = null, Font font = null, List <RichTextParseRule> rules = null) { return(RichText.ParseText(s, color, font, rules)); }