public void AddLine(Color color, bool bold, string text) { try { rtbChat.SelectionStart = rtbChat.Text.Length; rtbChat.SelectionColor = color; rtbChat.SelectionFont = new Font("Arial", 10, bold ? FontStyle.Bold : FontStyle.Regular); rtbChat.SelectedText = text; //+Environment.NewLine; AddEmotionsImages(text); rtbChat.ScrollToCaret(); rtbChat.SelectionStart = rtbChat.Text.Length; rtbChat.SelectedText = Environment.NewLine; } catch (Exception ex) { TestDebugger.Instance.WriteError(ex); } }
public static void ShowMessage(String message, ExRichTextBox richTextControl, RtfColor foreColor, RtfColor backGround, FontStyle textStyle, HorizontalAlignment textAlignment = HorizontalAlignment.Left, Single textSize = 10, String textFont = "Tahoma", int crlf = 1, Control setFocusTo = null, bool isMessage = true) { if (richTextControl != null && !richTextControl.IsDisposed) { //cleaning left-over RTF characters (avoid breaking RTB) if (message.IndexOf(@"\") > -1) { message = message.Replace(@"\", @"\\"); } if (message.IndexOf("{") > -1) { message = message.Replace("{", @"\{"); } if (message.IndexOf("}") > -1) { message = message.Replace("}", @"\}"); } if (message.IndexOf(Environment.NewLine) > -1) { message = message.Replace(Environment.NewLine, Environment.NewLine + @"\par "); } //we deal with the emoticons only if it is a chat message (ignore emoticons on system message) if (isMessage) { foreach (var icon in EmoticonsHelper.GetEmoticons()) { if (icon.Key.IndexOf(",") > -1) { var optionalToken = icon.Key.Split(','); foreach (var opt in optionalToken) { if (message.IndexOf(opt) > -1) { //replace the token with its RTF equivalent ;) message = message.Replace(opt, icon.Value); } } } else if (message.IndexOf(icon.Key) > -1) { message = message.Replace(icon.Key, icon.Value); } } } FontStyle extraStyles = new FontStyle(); if (message.IndexOf("") > -1) { extraStyles |= FontStyle.Bold; } Font extraFonts = new Font(textFont, textSize, textStyle | extraStyles, GraphicsUnit.Point); //add extra carriage returns if (crlf > 0) { for (int i = 0; i < crlf; i++) { message += Environment.NewLine; } } RTFFractionMessage messageFractions = new RTFFractionMessage(message, foreColor, backGround); try { if (message.IndexOf("\u0003") > -1) { string[] formattedParts = message.Split(new string[] { "\u0003" }, StringSplitOptions.None); for (int i = 0; i <= formattedParts.Count() - 1; i++) { if (formattedParts[i].Length > 1) { if (IntegerHelper.IsNumeric(formattedParts[i].Substring(0, 1))) { messageFractions = (ReturnRTFColor(formattedParts[i])); if (i < formattedParts.Length - 1) richTextControl.AppendTextAsRtf(messageFractions.Message, extraFonts, messageFractions.Forecolor, messageFractions.BackgroundColor); } else { messageFractions = new RTFFractionMessage(formattedParts[i], RtfColor.Black, RtfColor.White); richTextControl.AppendTextAsRtf(messageFractions.Message, extraFonts, messageFractions.Forecolor, messageFractions.BackgroundColor); } } } } } catch { //TODO: Handle } //write any extra text left richTextControl.AppendTextAsRtf(messageFractions.Message, extraFonts, messageFractions.Forecolor, messageFractions.BackgroundColor); //scroll to bottom of the RTB richTextControl.ScrollToCaret(); //if something else needs to be focused, focus that if (setFocusTo != null) { if (setFocusTo.CanFocus) { setFocusTo.Focus(); } } } }
public static void ShowMessage(String message, ExRichTextBox richTextControl, RtfColor foreColor, RtfColor backGround, FontStyle textStyle, HorizontalAlignment textAlignment = HorizontalAlignment.Left, Single textSize = 10, String textFont = "Tahoma", int crlf = 1, Control setFocusTo = null, bool isMessage = true) { if (richTextControl != null && !richTextControl.IsDisposed) { //cleaning left-over RTF characters (avoid breaking RTB) if (message.IndexOf(@"\") > -1) { message = message.Replace(@"\", @"\\"); } if (message.IndexOf("{") > -1) { message = message.Replace("{", @"\{"); } if (message.IndexOf("}") > -1) { message = message.Replace("}", @"\}"); } if (message.IndexOf(Environment.NewLine) > -1) { message = message.Replace(Environment.NewLine, Environment.NewLine + @"\par "); } //we deal with the emoticons only if it is a chat message (ignore emoticons on system message) if (isMessage) { foreach (var icon in EmoticonsHelper.GetEmoticons()) { if (icon.Key.IndexOf(",") > -1) { var optionalToken = icon.Key.Split(','); foreach (var opt in optionalToken) { if (message.IndexOf(opt) > -1) { //replace the token with its RTF equivalent ;) message = message.Replace(opt, icon.Value); } } } else if (message.IndexOf(icon.Key) > -1) { message = message.Replace(icon.Key, icon.Value); } } } FontStyle extraStyles = new FontStyle(); if (message.IndexOf("") > -1) { extraStyles |= FontStyle.Bold; } Font extraFonts = new Font(textFont, textSize, textStyle | extraStyles, GraphicsUnit.Point); //add extra carriage returns if (crlf > 0) { for (int i = 0; i < crlf; i++) { message += Environment.NewLine; } } RTFFractionMessage messageFractions = new RTFFractionMessage(message, foreColor, backGround); try { if (message.IndexOf("\u0003") > -1) { string[] formattedParts = message.Split(new string[] { "\u0003" }, StringSplitOptions.None); for (int i = 0; i <= formattedParts.Count() - 1; i++) { if (formattedParts[i].Length > 1) { if (IntegerHelper.IsNumeric(formattedParts[i].Substring(0, 1))) { messageFractions = (ReturnRTFColor(formattedParts[i])); if (i < formattedParts.Length - 1) { richTextControl.AppendTextAsRtf(messageFractions.Message, extraFonts, messageFractions.Forecolor, messageFractions.BackgroundColor); } } else { messageFractions = new RTFFractionMessage(formattedParts[i], RtfColor.Black, RtfColor.White); richTextControl.AppendTextAsRtf(messageFractions.Message, extraFonts, messageFractions.Forecolor, messageFractions.BackgroundColor); } } } } } catch { //TODO: Handle } //write any extra text left richTextControl.AppendTextAsRtf(messageFractions.Message, extraFonts, messageFractions.Forecolor, messageFractions.BackgroundColor); //scroll to bottom of the RTB richTextControl.ScrollToCaret(); //if something else needs to be focused, focus that if (setFocusTo != null) { if (setFocusTo.CanFocus) { setFocusTo.Focus(); } } } }