/// <summary> /// 获取Box中的所有内容。 /// </summary> /// <param name="containsForeignObject">内容中是否包含不是由IImagePathGetter管理的图片对象</param> /// <returns>key为位置,val为图片的ID</returns> public ChatBoxContent GetContent() { ChatBoxContent content = new ChatBoxContent(this.Text, this.Font, this.ForeColor); List <REOBJECT> list = this.RichEditOle.GetAllREOBJECT(); for (int i = 0; i < list.Count; i++) { uint pos = (uint)list[i].posistion; content.PicturePositions.Add(pos); if (list[i].dwUser != 10000) { content.AddEmotion(pos, list[i].dwUser); } else { GifBox box = (GifBox)Marshal.GetObjectForIUnknown(list[i].poleobj); content.AddForeignImage(pos, box.Image); } } return(content); }
public void AppendChatBoxContent(ChatBoxContent content, string userID, string mineID, string friendID) { try { if (content == null || content.Text == null) { return; } int count = this.Text.Length; if (content.EmotionDictionary != null) { string pureText = content.Text; //去掉表情和图片的占位符 List <uint> emotionPosList = new List <uint>(content.EmotionDictionary.Keys); List <uint> tempList = new List <uint>(); tempList.AddRange(emotionPosList); foreach (uint key in content.ForeignImageDictionary.Keys) { tempList.Add(key); } tempList.Sort(); for (int i = tempList.Count - 1; i >= 0; i--) { pureText = pureText.Remove((int)tempList[i], 1); } this.AppendText(pureText); //插入表情 for (int i = 0; i < tempList.Count; i++) { uint position = tempList[i]; if (emotionPosList.Contains(position)) { this.InsertDefaultEmotion(content.EmotionDictionary[position], (int)(count + position)); } else { this.InsertImage(content.ForeignImageDictionary[position], (int)(count + position)); } } this.Select(count, content.Text.Length); if (content.Color != null) { this.SelectionColor = content.Color; } if (content.Font != null) { this.SelectionFont = content.Font; } if (userID.Contains(mineID)) { this.SelectionAlignment = HorizontalAlignment.Right; Font f = new Font("宋体", 9, System.Drawing.FontStyle.Regular); Graphics g = this.CreateGraphics(); //单位为像素 g.PageUnit = GraphicsUnit.Display; SizeF sim = g.MeasureString(pureText, f); int a = this.Width;//当前聊天窗口中接收信息richtextbox的宽度 // int contentHeight = Convert.ToInt32(sim.Width) / a;//文本的行数 if (sim.Width <= a) { this.SelectionAlignment = HorizontalAlignment.Right; this.SelectionRightIndent = 10; } else { this.SelectionAlignment = HorizontalAlignment.Left; this.SelectionIndent = 10; } } if (userID.Contains(friendID)) { this.SelectionAlignment = HorizontalAlignment.Left; this.SelectionIndent = 10; } } else { this.AppendText(content.Text); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
public void AppendChatBoxContent(ChatBoxContent content) { try { if (content == null || content.Text == null) { return; } int count = this.Text.Length; if (content.EmotionDictionary != null) { string pureText = content.Text; //去掉表情和图片的占位符 List <uint> emotionPosList = new List <uint>(content.EmotionDictionary.Keys); List <uint> tempList = new List <uint>(); tempList.AddRange(emotionPosList); foreach (uint key in content.ForeignImageDictionary.Keys) { tempList.Add(key); } tempList.Sort(); for (int i = tempList.Count - 1; i >= 0; i--) { pureText = pureText.Remove((int)tempList[i], 1); } this.AppendText(pureText); //插入表情 for (int i = 0; i < tempList.Count; i++) { uint position = tempList[i]; if (emotionPosList.Contains(position)) { this.InsertDefaultEmotion(content.EmotionDictionary[position], (int)(count + position)); } else { this.InsertImage(content.ForeignImageDictionary[position], (int)(count + position)); } } } else { this.AppendText(content.Text); } this.Select(count, content.Text.Length); if (content.Color != null) { this.SelectionColor = content.Color; } if (content.Font != null) { this.SelectionFont = content.Font; } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
/// <summary> /// 获取Box中的所有内容。 /// </summary> /// <param name="containsForeignObject">内容中是否包含不是由IImagePathGetter管理的图片对象</param> /// <returns>key为位置,val为图片的ID</returns> public ChatBoxContent GetContent() { ChatBoxContent content = new ChatBoxContent(this.Text ,this.Font,this.ForeColor); List<REOBJECT> list = this.RichEditOle.GetAllREOBJECT(); for (int i = 0; i < list.Count; i++) { uint pos = (uint)list[i].posistion ; content.PicturePositions.Add(pos) ; if (list[i].dwUser != 10000) { content.AddEmotion(pos, list[i].dwUser); } else { GifBox box = (GifBox)Marshal.GetObjectForIUnknown(list[i].poleobj); content.AddForeignImage(pos, box.Image); } } return content; }
public void AppendChatBoxContent(ChatBoxContent content) { try { if (content == null || content.Text == null) { return; } int count = this.Text.Length; if (content.EmotionDictionary != null) { string pureText = content.Text; //去掉表情和图片的占位符 List<uint> emotionPosList = new List<uint>(content.EmotionDictionary.Keys); List<uint> tempList = new List<uint>(); tempList.AddRange(emotionPosList); foreach (uint key in content.ForeignImageDictionary.Keys) { tempList.Add(key); } tempList.Sort(); for (int i = tempList.Count - 1; i >= 0; i--) { pureText = pureText.Remove((int)tempList[i], 1); } this.AppendText(pureText); //插入表情 for (int i = 0; i < tempList.Count; i++) { uint position = tempList[i]; if (emotionPosList.Contains(position)) { this.InsertDefaultEmotion(content.EmotionDictionary[position], (int)(count + position)); } else { this.InsertImage(content.ForeignImageDictionary[position], (int)(count + position)); } } } else { this.AppendText(content.Text); } this.Select(count, content.Text.Length); if (content.Color != null) { this.SelectionColor = content.Color; } if (content.Font != null) { this.SelectionFont = content.Font; } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
public LastWordsRecord(string _speakerID, string _speakerName, bool me, ChatBoxContent content) { this.speakerID = _speakerID; this.speakerName = _speakerName; this.isMe = me; this.chatBoxContent = content; }