public RtfRichTextBox() { this.highlightColor = RtfColor.White; this.emotions = new Dictionary<string, Bitmap>(); this.rtfColor = new Dictionary<RtfColor, string>(); this.rtfFontFamily = new Dictionary<string, string>(); this.rtfColor.Add(RtfColor.Aqua, @"\red0\green255\blue255"); this.rtfColor.Add(RtfColor.Black, @"\red0\green0\blue0"); this.rtfColor.Add(RtfColor.Blue, @"\red0\green0\blue255"); this.rtfColor.Add(RtfColor.Fuchsia, @"\red255\green0\blue255"); this.rtfColor.Add(RtfColor.Gray, @"\red128\green128\blue128"); this.rtfColor.Add(RtfColor.Green, @"\red0\green128\blue0"); this.rtfColor.Add(RtfColor.Lime, @"\red0\green255\blue0"); this.rtfColor.Add(RtfColor.Maroon, @"\red128\green0\blue0"); this.rtfColor.Add(RtfColor.Navy, @"\red0\green0\blue128"); this.rtfColor.Add(RtfColor.Olive, @"\red128\green128\blue0"); this.rtfColor.Add(RtfColor.Purple, @"\red128\green0\blue128"); this.rtfColor.Add(RtfColor.Red, @"\red255\green0\blue0"); this.rtfColor.Add(RtfColor.Silver, @"\red192\green192\blue192"); this.rtfColor.Add(RtfColor.Teal, @"\red0\green128\blue128"); this.rtfColor.Add(RtfColor.White, @"\red255\green255\blue255"); this.rtfColor.Add(RtfColor.Yellow, @"\red255\green255\blue0"); this.rtfFontFamily.Add(FontFamily.GenericMonospace.Name, @"\fmodern"); this.rtfFontFamily.Add(FontFamily.GenericSansSerif.Name, @"\fswiss"); this.rtfFontFamily.Add(FontFamily.GenericSerif.Name, @"\froman"); this.rtfFontFamily.Add("UNKNOWN", @"\fnil"); using (Graphics graphics = base.CreateGraphics()) { this.xDpi = graphics.DpiX; this.yDpi = graphics.DpiY; } }
/// <summary> /// Appends a new paragraph. /// </summary> /// <param name="text">The text in the paragraph.</param> /// <param name="color">The color of the text.</param> public void AppendPar([NotNull] string text, RtfColor color) { #region Sanity checks if (text == null) throw new ArgumentNullException(nameof(text)); #endregion text = text.Replace(@"\", @"\\").Replace(Environment.NewLine, "\\par\n"); _builder.AppendLine("\\cf" + ((int)color + 1) + " " + text + "\\par\\par\n"); }
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(); } } } }
/// <summary> /// Appends the text. /// </summary> /// <param name="s">S.</param> /// <param name="message">Message.</param> public void AppendText(string s, MessageType message) { switch (message) { case MessageType.KeyboardInput: { if (Echo) { InsertTextAsRtf(s, this.CurrentFont, RtfColor.BrightYellow, RtfColor.Black); } break; } case MessageType.Normal: { if (boldFont && ((int) foreColor) < 8) { foreColor = (RtfColor) ((int) foreColor + 8); } InsertTextAsRtf(s, this.CurrentFont, foreColor, backColor); break; } case MessageType.Error: { InsertTextAsRtf(s, this.CurrentFont, RtfColor.BrightRed, RtfColor.BrightWhite); break; } case MessageType.ANSI: { ProcessANSI(s); break; } } }
private string GetColorTable(RtfColor _textColor, RtfColor _backColor) { StringBuilder builder = new StringBuilder(); builder.Append(@"{\colortbl ;"); builder.Append(this.rtfColor[_textColor]); builder.Append(";"); builder.Append(this.rtfColor[_backColor]); builder.Append(@";}\n"); return builder.ToString(); }
public RtfRichTextBox(RtfColor _textColor) : this() { this.textColor = _textColor; }
/// <summary> /// Crea la cadena RTF que define la tabla de colores de RTF /// {\colortbl ;[TEXT_COLOR];[HIGHLIGHT_COLOR];} /// </summary> private string GetColorTable(RtfColor clrText, RtfColor clrBack) { StringBuilder sbColorTable = new StringBuilder(); // Añade la cadena de la tabla de control sbColorTable.Append(@"{\colortbl ;"); // Añade el color del texto sbColorTable.Append(dicColor[clrText]); sbColorTable.Append(@";"); // Añade el color del fondo sbColorTable.Append(dicColor[clrBack]); sbColorTable.Append(@";}\n"); // Devuelve la cadena con la tabla return sbColorTable.ToString(); }
public void AppendTextAsRtf(string _text, Font _font, RtfColor _textColor, RtfColor _backColor) { base.Select(this.TextLength, 0); this.InsertTextAsRtf(_text, _font, _textColor, _backColor); }
/// <summary> /// Calls the default constructor then sets te text and highlight colors. /// </summary> /// <param name="_textColor"></param> /// <param name="_highlightColor"></param> public ExRichTextBox(RtfColor _textColor, RtfColor _highlightColor) : this() { textColor = _textColor; highlightColor = _highlightColor; }
public ExRichTextBox(RtfColor clrText) : this(clrText, RtfColor.White) { }
/// <summary> /// Imports the Cell properties into the RtfCell /// </summary> /// <param name="cell">The Cell to import</param> private void importCell(Cell cell) { _content = new ArrayList(); if (cell == null) { _borders = new RtfBorderGroup(_document, RtfBorder.CELL_BORDER, _parentRow.GetParentTable().GetBorders()); return; } colspan = cell.Colspan; rowspan = cell.Rowspan; if (cell.Rowspan > 1) { _mergeType = MergeVertParent; } if (cell is RtfCell) { _borders = new RtfBorderGroup(_document, RtfBorder.CELL_BORDER, ((RtfCell)cell).GetBorders()); } else { _borders = new RtfBorderGroup(_document, RtfBorder.CELL_BORDER, cell.Border, cell.BorderWidth, cell.BorderColor); } verticalAlignment = cell.VerticalAlignment; if (cell.BackgroundColor == null) { _backgroundColor = new RtfColor(_document, 255, 255, 255); } else { _backgroundColor = new RtfColor(_document, cell.BackgroundColor); } _cellPadding = (int)_parentRow.GetParentTable().GetCellPadding(); Paragraph container = null; foreach (IElement element in cell.Elements) { try { // should we wrap it in a paragraph if (!(element is Paragraph) && !(element is List)) { if (container != null) { container.Add(element); } else { container = new Paragraph(); container.Alignment = cell.HorizontalAlignment; container.Add(element); } } else { if (container != null) { IRtfBasicElement[] rtfElements = _document.GetMapper().MapElement(container); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); _content.Add(rtfElements[i]); } container = null; } // if horizontal alignment is undefined overwrite // with that of enclosing cell if (element is Paragraph && ((Paragraph)element).Alignment == ALIGN_UNDEFINED) { ((Paragraph)element).Alignment = cell.HorizontalAlignment; } IRtfBasicElement[] rtfElements2 = _document.GetMapper().MapElement(element); for (int i = 0; i < rtfElements2.Length; i++) { rtfElements2[i].SetInTable(true); _content.Add(rtfElements2[i]); } } } catch (DocumentException) { } } if (container != null) { try { IRtfBasicElement[] rtfElements = _document.GetMapper().MapElement(container); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); _content.Add(rtfElements[i]); } } catch (DocumentException) { } } }
/// <summary> /// Imports the Cell properties into the RtfCell /// @since 2.1.3 /// </summary> /// <param name="cell">The PdfPCell to import</param> private void importCell(PdfPCell cell) { _content = new ArrayList(); if (cell == null) { _borders = new RtfBorderGroup(_document, RtfBorder.CELL_BORDER, _parentRow.GetParentTable().GetBorders()); return; } // padding _cellPadding = (int)_parentRow.GetParentTable().GetCellPadding(); _cellPaddingBottom = cell.PaddingBottom; _cellPaddingTop = cell.PaddingTop; _cellPaddingRight = cell.PaddingRight; _cellPaddingLeft = cell.PaddingLeft; // BORDERS _borders = new RtfBorderGroup(_document, RtfBorder.CELL_BORDER, cell.Border, cell.BorderWidth, cell.BorderColor); // border colors border = cell.Border; borderColor = cell.BorderColor; borderColorBottom = cell.BorderColorBottom; borderColorTop = cell.BorderColorTop; borderColorLeft = cell.BorderColorLeft; borderColorRight = cell.BorderColorRight; // border widths borderWidth = cell.BorderWidth; borderWidthBottom = cell.BorderWidthBottom; borderWidthTop = cell.BorderWidthTop; borderWidthLeft = cell.BorderWidthLeft; borderWidthRight = cell.BorderWidthRight; colspan = cell.Colspan; rowspan = 1; //cell.GetRowspan(); // if (cell.GetRowspan() > 1) { // this.mergeType = MERGE_VERT_PARENT; // } verticalAlignment = cell.VerticalAlignment; if (cell.BackgroundColor == null) { _backgroundColor = new RtfColor(_document, 255, 255, 255); } else { _backgroundColor = new RtfColor(_document, cell.BackgroundColor); } // does it have column composite info? ArrayList compositeElements = cell.CompositeElements; if (compositeElements != null) { // does it have column info? Paragraph container = null; foreach (IElement element in compositeElements) { try { // should we wrap it in a paragraph if (!(element is Paragraph) && !(element is List)) { if (container != null) { container.Add(element); } else { container = new Paragraph(); container.Alignment = cell.HorizontalAlignment; container.Add(element); } } else { IRtfBasicElement[] rtfElements = null; if (container != null) { rtfElements = _document.GetMapper().MapElement(container); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); _content.Add(rtfElements[i]); } container = null; } // if horizontal alignment is undefined overwrite // with that of enclosing cell if (element is Paragraph && ((Paragraph)element).Alignment == ALIGN_UNDEFINED) { ((Paragraph)element).Alignment = cell.HorizontalAlignment; } rtfElements = _document.GetMapper().MapElement(element); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); _content.Add(rtfElements[i]); } } } catch (DocumentException) { } } if (container != null) { try { IRtfBasicElement[] rtfElements = _document.GetMapper().MapElement(container); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); _content.Add(rtfElements[i]); } } catch (DocumentException) { } } } // does it have image info? Image img = cell.Image; if (img != null) { try { IRtfBasicElement[] rtfElements = _document.GetMapper().MapElement(img); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); _content.Add(rtfElements[i]); } } catch (DocumentException) { } } // does it have phrase info? Phrase phrase = cell.Phrase; if (phrase != null) { try { IRtfBasicElement[] rtfElements = _document.GetMapper().MapElement(phrase); for (int i = 0; i < rtfElements.Length; i++) { rtfElements[i].SetInTable(true); _content.Add(rtfElements[i]); } } catch (DocumentException) { } } // does it have table info? PdfPTable table = cell.Table; if (table != null) { Add(table); // try { // RtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(table); // for (int i = 0; i < rtfElements.length; i++) { // rtfElements[i].SetInTable(true); // this.content.Add(rtfElements[i]); // } // } catch (DocumentException e) { // // TODO Auto-generated catch block // e.PrintStackTrace(); // } } }
private void ProcessParms(ArrayList parms) { int nowcol = 0; foreach (int i in parms) { switch (i) { case 0: //Reset/None { boldFont = false; foreColor = RtfColor.BrightWhite; backColor = RtfColor.Black; break; } case 1: //Bold { boldFont = true; break; } case 4: //Underscore { break; } case 5: //Blink { break; } case 7: //Reverse { break; } case 8: //Concealed { break; } case 30: case 31: case 32: case 33: case 34: case 35: case 36: case 37: { nowcol = i; break; } case 40: { backColor = RtfColor.Black; break; } case 41: { backColor = RtfColor.Red; break; } case 42: { backColor = RtfColor.Green; break; } case 43: { backColor = RtfColor.Yellow; break; } case 44: { backColor = RtfColor.Blue; break; } case 45: { backColor = RtfColor.Cyan; break; } case 46: { backColor = RtfColor.Magenta; break; } case 47: { backColor = RtfColor.White; break; } default: { break; } } //If it's a foreground color if (nowcol >= 30 && nowcol <= 37) { if (boldFont) { foreColor = (RtfColor) nowcol - 22; } else { foreColor = (RtfColor) nowcol - 30; } } } }
/// <summary> /// Imports a color value. The color number for the color defined /// by its red, green and blue values is determined and then the /// resulting mapping is added. /// </summary> /// <param name="colorNr">The original color number.</param> /// <param name="color">The color to import.</param> public void ImportColor(string colorNr, BaseColor color) { var rtfColor = new RtfColor(_rtfDoc, color); _importColorMapping[colorNr] = rtfColor.GetColorNumber().ToString(); }
public void AppendTextAsRtf(string _text, Font _font, RtfColor _textColor, RtfColor _backColor) { Select(TextLength, 0); InsertTextAsRtf(_text, _font, _textColor, _backColor); }
private string GetColorTable(RtfColor textColor, RtfColor backColor) { StringBuilder colorTable = new StringBuilder(); colorTable.Append(@"{\colortbl ;"); colorTable.Append(rtfColor[textColor]); colorTable.Append(@";"); colorTable.Append(rtfColor[backColor]); colorTable.Append(@";}\n"); return colorTable.ToString(); }
/// <summary> /// Inserts the text using the given font, text, and highlight colors. The /// text is wrapped in RTF codes so that the specified formatting is kept. /// You can only assign valid RTF to the RichTextBox.Rtf property, else /// an exception is thrown. The RTF string should follow this format ... /// /// {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{[FONTS]}{\colortbl ;[COLORS]}} /// \viewkind4\uc1\pard\cf1\f0\fs20 [DOCUMENT AREA] } /// /// </summary> /// <remarks> /// NOTE: The text is inserted wherever the caret is at the time of the call, /// and if any text is selected, that text is replaced. /// </remarks> /// <param name="_text"></param> /// <param name="_font"></param> /// <param name="_color"></param> /// <param name="_color"></param> public void InsertTextAsRtf(string _text, Font _font, RtfColor _textColor, RtfColor _backColor) { StringBuilder _rtf = new StringBuilder(); // Append the RTF header _rtf.Append(RTF_HEADER); // Create the font table from the font passed in and append it to the // RTF string _rtf.Append(GetFontTable(_font)); // Create the color table from the colors passed in and append it to the // RTF string _rtf.Append(GetColorTable(_textColor, _backColor)); // Create the document area from the text to be added as RTF and append // it to the RTF string. _rtf.Append(GetDocumentArea(_text, _font)); this.SelectedRtf = _rtf.ToString(); }
/// <summary> /// Initializes the text colors, creates dictionaries for RTF colors and /// font families, and stores the horizontal and vertical resolution of /// the RichTextBox's graphics context. /// </summary> public ExRichTextBox() : base() { // Initialize default text and background colors textColor = RtfColor.Black; highlightColor = RtfColor.White; // Initialize the dictionary mapping color codes to definitions rtfColor = new HybridDictionary(); rtfColor.Add(RtfColor.Aqua, RtfColorDef.Aqua); rtfColor.Add(RtfColor.Black, RtfColorDef.Black); rtfColor.Add(RtfColor.Blue, RtfColorDef.Blue); rtfColor.Add(RtfColor.Fuchsia, RtfColorDef.Fuchsia); rtfColor.Add(RtfColor.Gray, RtfColorDef.Gray); rtfColor.Add(RtfColor.Green, RtfColorDef.Green); rtfColor.Add(RtfColor.Lime, RtfColorDef.Lime); rtfColor.Add(RtfColor.Maroon, RtfColorDef.Maroon); rtfColor.Add(RtfColor.Navy, RtfColorDef.Navy); rtfColor.Add(RtfColor.Olive, RtfColorDef.Olive); rtfColor.Add(RtfColor.Purple, RtfColorDef.Purple); rtfColor.Add(RtfColor.Red, RtfColorDef.Red); rtfColor.Add(RtfColor.Silver, RtfColorDef.Silver); rtfColor.Add(RtfColor.Teal, RtfColorDef.Teal); rtfColor.Add(RtfColor.White, RtfColorDef.White); rtfColor.Add(RtfColor.Yellow, RtfColorDef.Yellow); // Initialize the dictionary mapping default Framework font families to // RTF font families rtfFontFamily = new HybridDictionary(); rtfFontFamily.Add(FontFamily.GenericMonospace.Name, RtfFontFamilyDef.Modern); rtfFontFamily.Add(FontFamily.GenericSansSerif, RtfFontFamilyDef.Swiss); rtfFontFamily.Add(FontFamily.GenericSerif, RtfFontFamilyDef.Roman); rtfFontFamily.Add(FF_UNKNOWN, RtfFontFamilyDef.Unknown); // Get the horizontal and vertical resolutions at which the object is // being displayed using(Graphics _graphics = this.CreateGraphics()) { xDpi = _graphics.DpiX; yDpi = _graphics.DpiY; } }
/// <summary> /// Inserta el texto utilizando la fuente y el color especificados /// </summary> public void InsertTextAsRtf(string _text, Font fntFont, RtfColor clrText) { InsertTextAsRtf(_text, fntFont, clrText, clrBack); }
/// <summary> /// Appends the text using the given font, text, and highlight colors. Simply /// moves the caret to the end of the RichTextBox's text and makes a call to /// insert. /// </summary> /// <param name="_text"></param> /// <param name="_font"></param> /// <param name="_textColor"></param> /// <param name="_backColor"></param> public void AppendTextAsRtf(string _text, Font _font, RtfColor _textColor, RtfColor _backColor) { // Move carret to the end of the text this.Select(this.TextLength, 0); InsertTextAsRtf(_text, _font, _textColor, _backColor); }
/// <summary> /// Calls the default constructor then sets the text color. /// </summary> /// <param name="_textColor"></param> public ExRichTextBox(RtfColor _textColor) : this() { textColor = _textColor; }
/// <summary> /// Añade el texto utilizando la fuente y el color especificado /// </summary> public void AppendTextAsRtf(string _text, Font fntFont, RtfColor clrText, RtfColor clrBack) { // Mueve el cursor al final del texto Select(TextLength, 0); // Inserta el texto InsertTextAsRtf(_text, fntFont, clrText, clrBack); }
public ExRichTextBox(RtfColor clrText) : this(clrText, RtfColor.White) {}
/// <summary> /// Appends the text using the given font and text color, and the current /// highlight color. /// </summary> /// <param name="_text"></param> /// <param name="_font"></param> /// <param name="_textColor"></param> public void AppendTextAsRtf(string _text, Font _font, RtfColor _textColor) { AppendTextAsRtf(_text, _font, _textColor, highlightColor); }
public void InsertTextAsRtf(string _text, Font _font, RtfColor _textColor, RtfColor _backColor) { StringBuilder builder = new StringBuilder(); builder.Append(@"{\rtf1\ansi\ansicpg936\deff0\deflang1033\deflangfe2052"); builder.Append(this.GetFontTable(_font)); builder.Append(this.GetColorTable(_textColor, _backColor)); builder.Append(this.GetDocumentArea(_text, _font)); base.SelectedRtf = builder.ToString(); }
/// <summary> /// Inserts the text using the given font and text color, and the current /// highlight color. /// </summary> /// <param name="_text"></param> /// <param name="_font"></param> /// <param name="_textColor"></param> public void InsertTextAsRtf(string _text, Font _font, RtfColor _textColor) { InsertTextAsRtf(_text, _font, _textColor, highlightColor); }
public ChatControler(ExRichTextBox chatbox, ChatMessage.MsgType type, RtfColor color) { ChatBox = chatbox; Type = type; Color = color; }
public RtfRichTextBox(RtfColor _textColor, RtfColor _highlightColor) : this() { this.textColor = _textColor; this.highlightColor = _highlightColor; }
public RTFFractionMessage(string Message, RtfColor Forecolor, RtfColor BackgroundColor) { _Message = Message; _ForeColor = Forecolor; _BackgroundColor = BackgroundColor; }
public void InsertTextAsRtf(string _text, Font _font, RtfColor _textColor, RtfColor _backColor) { StringBuilder builder = new StringBuilder(); builder.Append(RTF_HEADER); builder.Append(GetFontTable(_font)); builder.Append(GetColorTable(_textColor, _backColor)); builder.Append(GetDocumentArea(_text, _font)); SelectedRtf = builder.ToString(); }
/// <summary> /// Inserts the text as RTF. /// </summary> /// <param name="s">S.</param> /// <param name="font">Font.</param> /// <param name="textColor">Color of the text.</param> /// <param name="backColor">Color of the back.</param> public void InsertTextAsRtf(string s, Font font, RtfColor textColor, RtfColor backColor) { StringBuilder rtf = new StringBuilder(); rtf.Append(RTF_HEADER); rtf.Append(GetFontTable(font)); rtf.Append(GetColorTable(textColor, backColor)); rtf.Append(GetDocumentArea(s, font)); this.SelectionStart = int.MaxValue; this.SelectedRtf = rtf.ToString(); if (ScrollPos >= maxScroll) { //check to see if the buffer is too big //we have to do this while the user is scrolled //down incase the's looking at the line we're cutting out if (this.Text.Length > ScrollBufferSize && (this.Text.Length - ScrollBufferSize) > ScrollBufferSize/3) { this.SelectionStart = 0; string str = this.Text.Substring(0, this.Text.Length - ScrollBufferSize); int pos = this.Text.Length - ScrollBufferSize; //find the closest line to chop off at, otherwise default to //the ScrollBufferSize for (int i = str.Length - 1; i >= 0; i--) { if (str[i] == '\n') { pos = i; break; } } this.SelectionLength = pos; Win32Helper.SendMessage(this.Handle.ToInt32(), Win32Helper.EM_REPLACESEL, -1, ""); maxScroll = int.MinValue; ScrollToBottom(); maxScroll = ScrollPos; } else { maxScroll = Math.Max(ScrollPos, maxScroll); ScrollToBottom(); } } }
public ExRichTextBox(RtfColor clrText, RtfColor clrBack) { // Inicializa los colores de fondo y texto this.clrText = clrText; this.clrBack = clrBack; // Inicializa el diccionario de colores dicColor = new HybridDictionary(); dicColor.Add(RtfColor.Aqua, dicColorDef.Aqua); dicColor.Add(RtfColor.Black, dicColorDef.Black); dicColor.Add(RtfColor.Blue, dicColorDef.Blue); dicColor.Add(RtfColor.Fuchsia, dicColorDef.Fuchsia); dicColor.Add(RtfColor.Gray, dicColorDef.Gray); dicColor.Add(RtfColor.Green, dicColorDef.Green); dicColor.Add(RtfColor.Lime, dicColorDef.Lime); dicColor.Add(RtfColor.Maroon, dicColorDef.Maroon); dicColor.Add(RtfColor.Navy, dicColorDef.Navy); dicColor.Add(RtfColor.Olive, dicColorDef.Olive); dicColor.Add(RtfColor.Purple, dicColorDef.Purple); dicColor.Add(RtfColor.Red, dicColorDef.Red); dicColor.Add(RtfColor.Silver, dicColorDef.Silver); dicColor.Add(RtfColor.Teal, dicColorDef.Teal); dicColor.Add(RtfColor.White, dicColorDef.White); dicColor.Add(RtfColor.Yellow, dicColorDef.Yellow); // Inicializa el diccionario de fuentes dicFontFamily = new HybridDictionary(); dicFontFamily.Add(FontFamily.GenericMonospace.Name, dicFontFamilyDef.Modern); dicFontFamily.Add(FontFamily.GenericSansSerif, dicFontFamilyDef.Swiss); dicFontFamily.Add(FontFamily.GenericSerif, dicFontFamilyDef.Roman); dicFontFamily.Add(FF_UNKNOWN, dicFontFamilyDef.Unknown); }
/// <summary> /// Añade el texto utilizando la fuente y color especificado /// </summary> public void AppendTextAsRtf(string _text, Font fntFont, RtfColor clrText) { AppendTextAsRtf(_text, fntFont, clrText, clrBack); }
/// <summary> /// Appends the text using the given font and text color, and the current /// highlight color. /// </summary> /// <param name="_text"></param> /// <param name="_font"></param> /// <param name="_color"></param> public void AppendTextAsRtf(string _text, Font _font, RtfColor _textColor) { AppendTextAsRtf(_text, _font, _textColor, highlightColor); }
/// <summary> /// Inserts the text using the given font and text color, and the current /// highlight color. /// </summary> /// <param name="_text"></param> /// <param name="_font"></param> /// <param name="_color"></param> public void InsertTextAsRtf(string _text, Font _font, RtfColor _textColor) { InsertTextAsRtf(_text, _font, _textColor, highlightColor); }
/// <summary> /// Inserta el texto utilizando la fuente y el color especificados /// </summary> public void InsertTextAsRtf(string _text, Font fntFont, RtfColor clrText, RtfColor clrBack) { StringBuilder sbRtf = new StringBuilder(); // Añade la cabecera RTF sbRtf.Append(RTF_HEADER); // Crea la tabla de fuentes a partir de la fuente pasada y la añade a la cadena RTF sbRtf.Append(GetFontTable(fntFont)); // Crea la tabla de color a partir de los colores pasados y la añade a la cadena RTF sbRtf.Append(GetColorTable(clrText, clrBack)); // Crea el área del doucmento a partir del texto a añadir como RTF sbRtf.Append(GetDocumentArea(_text, fntFont)); // Añade el texto a la cadena RTF SelectedRtf = sbRtf.ToString(); }
/// <summary> /// Creates a font table from the RtfColor structure. When an Insert or Append /// operation is performed, _textColor and _backColor are either specified /// or the default is used. In any case, on any Insert or Append, only three /// colors are used. The default color of the RichTextBox (signified by a /// semicolon (;) without a definition), is always the first color (index 0) in /// the color table. The second color is always the text color, and the third /// is always the highlight color (color behind the text). The color table /// should have the form ... /// /// {\colortbl ;[TEXT_COLOR];[HIGHLIGHT_COLOR];} /// /// </summary> /// <param name="_textColor"></param> /// <param name="_backColor"></param> /// <returns></returns> private string GetColorTable(RtfColor _textColor, RtfColor _backColor) { StringBuilder _colorTable = new StringBuilder(); // Append color table control string and default font (;) _colorTable.Append(@"{\colortbl ;"); // Append the text color _colorTable.Append(rtfColor[_textColor]); _colorTable.Append(@";"); // Append the highlight color _colorTable.Append(rtfColor[_backColor]); _colorTable.Append(@";}\n"); return _colorTable.ToString(); }