/// <summary> /// Adds an entry to the chat history box. /// </summary> /// <param name="text">The text to be added.</param> private void UpdateChatHistory(string text, FormatTypes formatType) { // This code block ensures optimum line spacing between different types of formatted texts. switch (lastFormatType) { case FormatTypes.Status: if (formatType != FormatTypes.Status) { rtbMessageHistory.AppendTextAsRtf("\n"); } break; case FormatTypes.Message: if (formatType != FormatTypes.UserName) { rtbMessageHistory.AppendTextAsRtf("\n"); } break; } lastFormatType = formatType; // Ensure there is no more than one blank line between messages. if (text.StartsWith(Environment.NewLine)) { if (rtbMessageHistory.Text.EndsWith("\n\n")) { text = text.TrimStart(Environment.NewLine.ToCharArray()); } } switch (formatType) { case FormatTypes.UserName: case FormatTypes.Status: rtbMessageHistory.AppendTextAsRtf(text, Definitions.GetPresetFont(formatType), Definitions.GetPresetColor(formatType)); break; case FormatTypes.Message: string rtfText = DecodeEmoticons(text); rtfText = rtfText.Insert(rtfText.LastIndexOf(@"\f0"), @"\li240"); rtbMessageHistory.AppendRtf(rtfText); // Enable button that saves chat history. if (!bCanSave && rtbMessageHistory.TextLength > 0) { tbBtnSave.Enabled = true; bCanSave = true; } break; default: rtbMessageHistory.AppendTextAsRtf(text); break; } // For auto scrolling chat history box. rtbMessageHistory.ScrollToBottom(); }