예제 #1
0
 private void OnReceivedMsg(string msg)
 {
     try
     {
         var userName = string.Empty;
         var json     = string.Empty;
         var content  = new GFF.Component.ChatBox.ChatBoxContent();
         if (!string.IsNullOrEmpty(msg) && (msg.IndexOf("|") > -1))
         {
             userName = msg.Substring(0, msg.IndexOf("|"));
             json     = msg.Substring(msg.IndexOf("|") + 1);
             try
             {
                 content = SerializeHelper.Deserialize <GFF.Component.ChatBox.ChatBoxContent>(json);
             }
             catch {
                 return;
             }
             content = SerializeHelper.Deserialize <GFF.Component.ChatBox.ChatBoxContent>(json);
             FriendHelper.Set(userName);
         }
         if (userName != qqUser.DisplayName)
         {
             if (content.Text == "发送了一个抖动提醒。\n")
             {
                 chatBoxSend.Focus();
                 VibrationHelper.Vibration(this);
             }
         }
         if (content.Text.IndexOf("[img=") > -1)
         {
             var fileUrls = content.Text.Split(new[] { @"\r\n" }, StringSplitOptions.None);
             foreach (var item in fileUrls)
             {
                 var imageUrl = item.Substring(item.IndexOf("[img=") + 5);
                 imageUrl = imageUrl.Substring(0, imageUrl.IndexOf("]"));
                 var img = ImageHelper.FromUrl(imageUrl);
                 content.AddForeignImage(0, img);
             }
             content.Text = " ";
         }
         if (content.Text.IndexOf("[file=") > -1)
         {
             var fileUrls = content.Text.Split(new[] { @"\r\n" }, StringSplitOptions.None);
             content.Text = "";
             foreach (var item in fileUrls)
             {
                 var fileUrl = item.Substring(item.IndexOf("[file=") + 6);
                 fileUrl       = fileUrl.Substring(0, fileUrl.IndexOf("]"));
                 content.Text += fileUrl + Environment.NewLine;
             }
         }
         AppendChatBoxContent(userName, null, content, Color.Blue, false);
     }
     catch
     {
     }
 }
예제 #2
0
파일: ChatBox.cs 프로젝트: zhangx3000/GFF
        /// <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);
        }