示例#1
0
文件: MainForm.cs 项目: yswenli/GFF
 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 (Exception ex)
     {
         MessageBox.Show("发送图片失败:" + ex.Message);
     }
 }
示例#2
0
        private void toolZhenDong_Click(object sender, EventArgs e)
        {
            var msg = "发送了一个抖动提醒。\n";

            //this.AppendMessage(this.QQUser.DisplayName, Color.Green, msg);
            chatBoxSend.Focus();
            VibrationHelper.Vibration(this);
            var content = new GFF.Component.ChatBox.ChatBoxContent();

            content.Text = msg;
            SendMsgToServer(SerializeHelper.Serialize(content));
        }