public new void AppendText(string strText) { List<STextChange> lstChanges = new List<STextChange>(); int iCarets = 0; int iAppendedStartPosition = -1; int iAppendedTextLength = -1; if ((iCarets = this.GetCaretCount(strText)) > 0) { iAppendedStartPosition = this.Text.Length; iAppendedTextLength = strText.Length; int i = -1; int iFoundCarets = 0; bool blFindingColourCodes = false; string strColourCode = String.Empty; char cFontCode = 'n'; do { i = -1; blFindingColourCodes = false; //if ((i = this.Find("^", this.Text.Length - iConsoleOutputLength - 1, this.Text.Length, RichTextBoxFinds.MatchCase)) > 0) { if ((i = this.FindCaretCode(strText, iAppendedTextLength)) >= 0) { if (i < iAppendedTextLength - 1 && char.IsDigit(strText[i + 1]) == true) { STextChange stcChange = new STextChange(); stcChange.m_iPosition = i; strColourCode = strText.Substring(i, 2); // Remove the ^[0-9] strText = strText.Substring(0, i) + strText.Substring(i + 2); iAppendedTextLength -= 2; if (this.m_dicChatTextColours.ContainsKey(strColourCode) == true) { stcChange.m_clTextColour = this.m_dicChatTextColours[strColourCode]; } lstChanges.Add(stcChange); blFindingColourCodes = true; } else if (i < iAppendedTextLength - 1 && ((cFontCode = strText[i + 1]) == 'b' || strText[i + 1] == 'n' || strText[i + 1] == 'i')) { STextChange stcChange = new STextChange(); stcChange.m_iPosition = i; switch (cFontCode) { case 'n': stcChange.m_fntTextFont = this.Font;// new Font("Calibri", 10); break; case 'b': stcChange.m_fntTextFont = new Font(this.Font, FontStyle.Bold); //new Font("Calibri", 10, FontStyle.Bold); break; case 'i': stcChange.m_fntTextFont = new Font(this.Font, FontStyle.Italic); //new Font("Calibri", 10, FontStyle.Italic); break; default: break; } // Remove the ^[b|n|i] strText = strText.Substring(0, i) + strText.Substring(i + 2); iAppendedTextLength -= 2; lstChanges.Add(stcChange); blFindingColourCodes = true; } // Just stops that last pass of the string when we know how many times // it should pass anyway. iFoundCarets++; } } while (blFindingColourCodes == true && iFoundCarets < iCarets); while ((i = strText.IndexOf("^^")) > 0) { strText = strText.Substring(0, i) + "^" + strText.Substring(i + 2); iAppendedTextLength--; } } base.AppendText(strText); if (iAppendedStartPosition >= 0) { foreach (STextChange stcChange in lstChanges) { this.Select(iAppendedStartPosition + stcChange.m_iPosition, iAppendedTextLength - stcChange.m_iPosition); if (stcChange.m_fntTextFont != null) { this.SelectionFont = stcChange.m_fntTextFont; } else { this.SelectionColor = stcChange.m_clTextColour; } } } }
protected void FlushBuffer() { String text = null; lock (this.AppendTextBufferLock) { text = this.AppendTextBuffer; this.AppendTextBuffer = ""; } if (String.IsNullOrEmpty(text) == false) { this.InvokeIfRequired(() => { List<STextChange> changes = new List<STextChange>(); int carets = 0; int appendedStartPosition = -1; int appendedTextLength = -1; if ((carets = GetCaretCount(text)) > 0) { appendedStartPosition = this.Text.Length; appendedTextLength = text.Length; int i = -1; int foundCarets = 0; bool findingColourCodes = false; string colourCode = String.Empty; do { i = -1; findingColourCodes = false; //if ((i = this.Find("^", this.Text.Length - iConsoleOutputLength - 1, this.Text.Length, RichTextBoxFinds.MatchCase)) > 0) { if ((i = FindCaretCode(text, appendedTextLength)) >= 0) { if (i < appendedTextLength - 1 && char.IsDigit(text[i + 1]) == true) { STextChange change = new STextChange { Position = i }; colourCode = text.Substring(i, 2); // Remove the ^[0-9] text = text.Substring(0, i) + text.Substring(i + 2); appendedTextLength -= 2; if (this.ChatTextColours.ContainsKey(colourCode) == true) { change.Colour = this.ChatTextColours[colourCode]; } changes.Add(change); findingColourCodes = true; } else { char fontCode = 'n'; if (i < appendedTextLength - 1 && ((fontCode = text[i + 1]) == 'b' || text[i + 1] == 'n' || text[i + 1] == 'i')) { STextChange stcChange = new STextChange { Position = i }; switch (fontCode) { case 'n': stcChange.Font = this.Font;// new Font("Calibri", 10); break; case 'b': stcChange.Font = new Font(this.Font, FontStyle.Bold); //new Font("Calibri", 10, FontStyle.Bold); break; case 'i': stcChange.Font = new Font(this.Font, FontStyle.Italic); //new Font("Calibri", 10, FontStyle.Italic); break; } // Remove the ^[b|n|i] text = text.Substring(0, i) + text.Substring(i + 2); appendedTextLength -= 2; changes.Add(stcChange); findingColourCodes = true; } } // Just stops that last pass of the string when we know how many times // it should pass anyway. foundCarets++; } } while (findingColourCodes == true && foundCarets < carets); while ((i = text.IndexOf("^^", System.StringComparison.Ordinal)) > 0) { text = text.Substring(0, i) + "^" + text.Substring(i + 2); appendedTextLength--; } } this.InternalAppend(text); base.AppendText(text); if (appendedStartPosition >= 0) { foreach (STextChange change in changes) { this.Select(appendedStartPosition + change.Position, appendedTextLength - change.Position); if (change.Font != null) { this.SelectionFont = change.Font; } this.SelectionColor = change.Colour; } } this.OnFlushed(); }); } }
public new void AppendText(string strText) { List <STextChange> lstChanges = new List <STextChange>(); int iCarets = 0; int iAppendedStartPosition = -1; int iAppendedTextLength = -1; if ((iCarets = this.GetCaretCount(strText)) > 0) { iAppendedStartPosition = this.Text.Length; iAppendedTextLength = strText.Length; int i = -1; int iFoundCarets = 0; bool blFindingColourCodes = false; string strColourCode = String.Empty; char cFontCode = 'n'; do { i = -1; blFindingColourCodes = false; //if ((i = this.Find("^", this.Text.Length - iConsoleOutputLength - 1, this.Text.Length, RichTextBoxFinds.MatchCase)) > 0) { if ((i = this.FindCaretCode(strText, iAppendedTextLength)) >= 0) { if (i < iAppendedTextLength - 1 && char.IsDigit(strText[i + 1]) == true) { STextChange stcChange = new STextChange(); stcChange.m_iPosition = i; strColourCode = strText.Substring(i, 2); // Remove the ^[0-9] strText = strText.Substring(0, i) + strText.Substring(i + 2); iAppendedTextLength -= 2; if (this.m_dicChatTextColours.ContainsKey(strColourCode) == true) { stcChange.m_clTextColour = this.m_dicChatTextColours[strColourCode]; } lstChanges.Add(stcChange); blFindingColourCodes = true; } else if (i < iAppendedTextLength - 1 && ((cFontCode = strText[i + 1]) == 'b' || strText[i + 1] == 'n' || strText[i + 1] == 'i')) { STextChange stcChange = new STextChange(); stcChange.m_iPosition = i; switch (cFontCode) { case 'n': stcChange.m_fntTextFont = this.Font; // new Font("Calibri", 10); break; case 'b': stcChange.m_fntTextFont = new Font(this.Font, FontStyle.Bold); //new Font("Calibri", 10, FontStyle.Bold); break; case 'i': stcChange.m_fntTextFont = new Font(this.Font, FontStyle.Italic); //new Font("Calibri", 10, FontStyle.Italic); break; default: break; } // Remove the ^[b|n|i] strText = strText.Substring(0, i) + strText.Substring(i + 2); iAppendedTextLength -= 2; lstChanges.Add(stcChange); blFindingColourCodes = true; } // Just stops that last pass of the string when we know how many times // it should pass anyway. iFoundCarets++; } } while (blFindingColourCodes == true && iFoundCarets < iCarets); while ((i = strText.IndexOf("^^")) > 0) { strText = strText.Substring(0, i) + "^" + strText.Substring(i + 2); iAppendedTextLength--; } } this.InternalAppend(strText); base.AppendText(strText); if (iAppendedStartPosition >= 0) { foreach (STextChange stcChange in lstChanges) { this.Select(iAppendedStartPosition + stcChange.m_iPosition, iAppendedTextLength - stcChange.m_iPosition); if (stcChange.m_fntTextFont != null) { this.SelectionFont = stcChange.m_fntTextFont; } else { this.SelectionColor = stcChange.m_clTextColour; } } } }
protected void FlushBuffer() { String text = null; lock (this.AppendTextBufferLock) { text = this.AppendTextBuffer; this.AppendTextBuffer = ""; } if (String.IsNullOrEmpty(text) == false) { this.InvokeIfRequired(() => { List <STextChange> changes = new List <STextChange>(); int carets = 0; int appendedStartPosition = -1; int appendedTextLength = -1; if ((carets = GetCaretCount(text)) > 0) { appendedStartPosition = this.Text.Length; appendedTextLength = text.Length; int i = -1; int foundCarets = 0; bool findingColourCodes = false; string colourCode = String.Empty; do { i = -1; findingColourCodes = false; //if ((i = this.Find("^", this.Text.Length - iConsoleOutputLength - 1, this.Text.Length, RichTextBoxFinds.MatchCase)) > 0) { if ((i = FindCaretCode(text, appendedTextLength)) >= 0) { if (i < appendedTextLength - 1 && char.IsDigit(text[i + 1]) == true) { STextChange change = new STextChange { Position = i }; colourCode = text.Substring(i, 2); // Remove the ^[0-9] text = text.Substring(0, i) + text.Substring(i + 2); appendedTextLength -= 2; if (this.ChatTextColours.ContainsKey(colourCode) == true) { change.Colour = this.ChatTextColours[colourCode]; } changes.Add(change); findingColourCodes = true; } else { char fontCode = 'n'; if (i < appendedTextLength - 1 && ((fontCode = text[i + 1]) == 'b' || text[i + 1] == 'n' || text[i + 1] == 'i')) { STextChange stcChange = new STextChange { Position = i }; switch (fontCode) { case 'n': stcChange.Font = this.Font; // new Font("Calibri", 10); break; case 'b': stcChange.Font = new Font(this.Font, FontStyle.Bold); //new Font("Calibri", 10, FontStyle.Bold); break; case 'i': stcChange.Font = new Font(this.Font, FontStyle.Italic); //new Font("Calibri", 10, FontStyle.Italic); break; } // Remove the ^[b|n|i] text = text.Substring(0, i) + text.Substring(i + 2); appendedTextLength -= 2; changes.Add(stcChange); findingColourCodes = true; } } // Just stops that last pass of the string when we know how many times // it should pass anyway. foundCarets++; } } while (findingColourCodes == true && foundCarets < carets); while ((i = text.IndexOf("^^", System.StringComparison.Ordinal)) > 0) { text = text.Substring(0, i) + "^" + text.Substring(i + 2); appendedTextLength--; } } this.InternalAppend(text); base.AppendText(text); if (appendedStartPosition >= 0) { foreach (STextChange change in changes) { this.Select(appendedStartPosition + change.Position, appendedTextLength - change.Position); if (change.Font != null) { this.SelectionFont = change.Font; } this.SelectionColor = change.Colour; } } this.OnFlushed(); }); } }