Ejemplo n.º 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 (Exception ex)
     {
         MessageBox.Show("发送图片失败:" + ex.Message);
     }
 }
Ejemplo n.º 2
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            var content = chatBoxSend.GetContent();

            //发送内容为空时,不做响应
            if (content.IsEmpty())
            {
                return;
            }

            var url = string.Empty;

            if (content.ContainsForeignImage())
            {
                foreach (var item in content.ForeignImageDictionary)
                {
                    try
                    {
                        url += string.Format("[img={0}]{1}", ImageHelper.ToUrl(PushHelper.Client.Url, item.Value),
                                             Environment.NewLine);
                    }
                    catch
                    {
                    }
                }
                content.ForeignImageDictionary.Clear();
                content.Text = url;
            }
            var msgtxt = content.Text;

            //清空发送输入框
            chatBoxSend.Text = string.Empty;
            chatBoxSend.Focus();

            if (string.IsNullOrEmpty(msgtxt) && (content.EmotionDictionary.Count == 0))
            {
                return;
            }

            GFF.Component.ChatBox.ChatBoxContent c = new GFF.Component.ChatBox.ChatBoxContent();
            c.Text = msgtxt;
            c.EmotionDictionary = content.EmotionDictionary;
            c.PicturePositions  = content.PicturePositions;
            c.Font  = content.Font;
            c.Color = content.Color;
            string msg = SerializeHelper.Serialize(c);

            ThreadPool.QueueUserWorkItem(s => SendMsgToServer(msg));
        }
Ejemplo n.º 3
0
 private void ToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     openFileDialog1.Title            = "请选择图片";
     openFileDialog1.CheckFileExists  = true;
     openFileDialog1.CheckPathExists  = true;
     openFileDialog1.Filter           = "图片|*.jpg;*.png;*.bmp;*.gif";
     openFileDialog1.Multiselect      = false;
     openFileDialog1.InitialDirectory = Environment.SpecialFolder.MyPictures.ToString();
     openFileDialog1.FileName         = string.Empty;
     if (openFileDialog1.ShowDialog() == DialogResult.OK)
     {
         loadingTxt.Show();
         chatBoxSend.Enabled = false;
         this.InvokeAction(() =>
         {
             var img = ImageHelper.MakeThumbnail(Image.FromFile(openFileDialog1.FileName), 200, 100);
             chatBoxSend.InsertImage(img);
             loadingTxt.Hide();
             chatBoxSend.Enabled = true;
             chatBoxSend.Focus();
             chatBoxSend.ScrollToCaret();
         });
     }
 }