public void InsertTextAsRtf(string _text, Font _font, RtfRichTextBox.RtfColor _textColor, RtfRichTextBox.RtfColor _backColor) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("{\\rtf1\\ansi\\ansicpg936\\deff0\\deflang1033\\deflangfe2052"); stringBuilder.Append(this.GetFontTable(_font)); stringBuilder.Append(this.GetColorTable(_textColor, _backColor)); stringBuilder.Append(this.GetDocumentArea(_text, _font)); this.SelectedRtf = ((object)stringBuilder).ToString(); }
private string GetColorTable(RtfRichTextBox.RtfColor _textColor, RtfRichTextBox.RtfColor _backColor) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("{\\colortbl ;"); stringBuilder.Append(this.rtfColor[_textColor]); stringBuilder.Append(";"); stringBuilder.Append(this.rtfColor[_backColor]); stringBuilder.Append(";}\\n"); return(((object)stringBuilder).ToString()); }
//追加消息 private void AppendMessage(string userName, RtfRichTextBox.RtfColor color, DateTime?originTime, string msg, bool isRtf) { if (string.IsNullOrWhiteSpace(msg)) { return; } DateTime showTime = DateTime.Now; this.rtfRichTextBox_history.AppendTextAsRtf(string.Format("{0} {1}\n", "网页用户", showTime), new Font(this.Font, FontStyle.Regular), color); //this.rtfRichTextBox_history.AppendText("adsfasdf"); this.rtfRichTextBox_history.AppendText(msg); this.rtfRichTextBox_history.AppendText("\n"); }
public void ServerMsgToChatRecords(MsgType msgType, string msgContent, RtfRichTextBox.RtfColor color = RtfRichTextBox.RtfColor.SeaGreen, bool isRtf = true) { if (GetServerMsgDel == null) { isExistsChatForm = false; isShowPanel = true; //将信息添加到集合里面 notReadMsg_list.Add(new GGUserInfo() { userNickName = user.userNickName, userImg = "1.png" }, msgContent); } else { GetServerMsgDel(msgType, msgContent, color, isRtf); } }
private void AppendMessage(string userName, RtfRichTextBox.RtfColor color, DateTime?originTime, string msg, bool isRtf) { if (string.IsNullOrWhiteSpace(msg)) { return; } DateTime showTime = DateTime.Now; this.txtAllMsg.AppendTextAsRtf(string.Format("{0} {1}\n", userName, showTime), new Font(this.Font, FontStyle.Regular), color); if (isRtf) { this.txtAllMsg.AppendRtf(msg); } else { this.txtAllMsg.AppendText(msg); } this.txtAllMsg.Select(this.txtAllMsg.Text.Length, 0); this.txtAllMsg.ScrollToCaret(); }
/// <summary> /// 设置颜色 /// </summary> /// <param name="index"></param> /// <returns></returns> public static RtfRichTextBox.RtfColor GetColor(int index) { RtfRichTextBox.RtfColor color = colorArr[index]; return(color); }
private void AppendMsgToServerChatList(string msgContent, string userName = null, bool isRtf = true, RtfRichTextBox.RtfColor color = RtfRichTextBox.RtfColor.Green) { string newSendName = ""; string newMsgContent = ""; string[] arr = msgContent.Split('|'); if (arr.Length > 1) { newSendName = arr[0]; newMsgContent = arr[1].Replace("\0", ""); } else { newSendName = ""; newMsgContent = msgContent; } this.serverChatRecords.AppendTextAsRtf(string.Format("{0} {1}", newSendName, DateTime.Now), new Font(this.Font, FontStyle.Regular), color); this.serverChatRecords.AppendTextAsRtf(Environment.NewLine); if (isRtf) { try { this.serverChatRecords.AppendRtf(newMsgContent); } catch (Exception ex) { newMsgContent = newMsgContent.Replace("\0", ""); this.serverChatRecords.AppendText(newMsgContent); this.serverChatRecords.AppendTextAsRtf(Environment.NewLine); } } else { newMsgContent = newMsgContent.Replace("\0", ""); this.serverChatRecords.AppendText(newMsgContent); this.serverChatRecords.AppendTextAsRtf(Environment.NewLine); } serverChatRecords.ScrollToCaret(); }
public void InsertTextAsRtf(string _text, Font _font, RtfRichTextBox.RtfColor _textColor) { this.InsertTextAsRtf(_text, _font, _textColor, this.highlightColor); }
public void AppendTextAsRtf(string _text, Font _font, RtfRichTextBox.RtfColor _textColor, RtfRichTextBox.RtfColor _backColor) { this.Select(this.TextLength, 0); this.InsertTextAsRtf(_text, _font, _textColor, _backColor); }
public RtfRichTextBox(RtfRichTextBox.RtfColor _textColor, RtfRichTextBox.RtfColor _highlightColor) : this() { this.textColor = _textColor; this.highlightColor = _highlightColor; }
public RtfRichTextBox(RtfRichTextBox.RtfColor _textColor) : this() { this.textColor = _textColor; }