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); } }
private void ToolFile_Click(object sender, EventArgs e) { openFileDialog1.Title = "请选择文件"; openFileDialog1.CheckFileExists = true; openFileDialog1.CheckPathExists = true; openFileDialog1.Filter = "文件|*.*"; openFileDialog1.Multiselect = false; openFileDialog1.InitialDirectory = Environment.SpecialFolder.MyPictures.ToString(); openFileDialog1.FileName = string.Empty; if (openFileDialog1.ShowDialog() == DialogResult.OK) { PushHelper.HttpSendFileAsync(openFileDialog1.FileName, url => { try { var fileUrl = string.Format("[file={0}]{1}", url, Environment.NewLine); var content = new GFF.Component.ChatBox.ChatBoxContent(); content.Text = fileUrl; SendMsgToServer(SerializeHelper.Serialize(content)); } catch { } }); } }
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)); }
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}", ClientConfig.Instance().Url + ImageHelper.ToUrl(ClientConfig.Instance().Url + "Upload", 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)); }
/// <summary> /// 发送信息文本到内容框 /// </summary> /// <param name="userName">名字</param> /// <param name="originTime">时间</param> /// <param name="content">发送内容</param> /// <param name="color">字体颜色</param> /// <param name="followingWords">是否有用户名</param> /// <param name="offlineMessage">是否在线消息</param> private void AppendChatBoxContent(string userName, DateTime?originTime, GFF.Component.ChatBox.ChatBoxContent content, Color color, bool followingWords, bool offlineMessage) { if (InvokeRequired) { BeginInvoke( new Action( () => { AppendChatBoxContent(userName, originTime, content, color, followingWords, offlineMessage); })); } else { if (!followingWords) { var showTime = DateTime.Now.ToLongTimeString(); if (!offlineMessage && (originTime != null)) { showTime = originTime.Value.ToString(); } if (userName == QQUser.DisplayName) { color = Color.YellowGreen; } chatBox_history.AppendRichText(string.Format("{0} {1}\n", userName, showTime), new Font(messageFont, FontStyle.Regular), color); if ((originTime != null) && offlineMessage) { chatBox_history.AppendText(string.Format(" [{0} 离线消息] ", originTime.Value)); } else { chatBox_history.AppendText(" "); } } else { chatBox_history.AppendText(" ."); } chatBox_history.AppendChatBoxContent(content); chatBox_history.AppendText(" \n"); chatBox_history.Focus(); chatBox_history.Select(chatBox_history.Text.Length, 0); chatBox_history.ScrollToCaret(); chatBoxSend.Focus(); } }
/// <summary> /// 发送信息文本到内容框 /// </summary> /// <param name="userName">名字</param> /// <param name="originTime">时间</param> /// <param name="content">发送内容</param> /// <param name="color">字体颜色</param> /// <param name="followingWords">是否有用户名</param> private void AppendChatBoxContent(string userName, DateTime?originTime, GFF.Component.ChatBox.ChatBoxContent content, Color color, bool followingWords) { AppendChatBoxContent(userName, originTime, content, color, followingWords, originTime != null); }
private void OnReceivedMsg(GFF.Component.ChatBox.ChatBoxContent content, DateTime?originTime) { AppendChatBoxContent(lblChatName.Tag == null ? "斯" : lblChatName.Tag.ToString(), originTime, content, Color.Blue, false); }