示例#1
0
        public ChatForm(Jid jid, XmppClientConnection con, string nickname)
        {
            InitializeComponent();

            _emotion = new EmotionDropdown();
            AcceptInit = new AcceptInitDelegate(AcceptInitMethod);
            ReturnAcceptInit = new ReturnAcceptInitDelegate(ReturnAcceptMethod);
            AcceptOpen = new AcceptOpenDelegate(AcceptOpenMethod);
            FileSendRequestEvent = new FileSendRequestDelegate(onUserFileSendRequest);
            FileSendInitEvent = new FileSendInitDelegate(FileSendInit);

            to_Jid = jid;
            _connection = con;
            _nickname = jid.User;
            this.nikeName.Text = nickname;

            VcardIq viq = new VcardIq(IqType.get, new Jid(jid.Bare));
            packetId = viq.Id;
            _connection.IqGrabber.SendIq(viq, new IqCB(VcardResult), null, true);

            Util.ChatForms.Add(to_Jid.Bare.ToLower(), this);
            nikeName.Text = _nickname;

            con.MessageGrabber.Add(jid, new BareJidComparer(), new MessageCB(MessageCallback), null);
            _emotion.EmotionContainer.ItemClick += new UI.Face.EmotionItemMouseEventHandler(EmotionContainer_ItemClick);

            friendHead.BackgroundImage = ResClass.GetImgRes("Padding4Normal");
            friendHead.Image = ResClass.GetHead("big194");

            rtfSend.AllowDrop = true;

            rtfSend.DragDrop += new DragEventHandler(rtfSend_DragDrop);
            rtfSend.DragEnter += new DragEventHandler(rtfSend_DragEnter);
        }
示例#2
0
        public ChatGroupForm(Jid jid, XmppClientConnection con, string nickname)
        {
            InitializeComponent();
            friend_list.OpenChatEvent += new ChatGroupListView.delegate_openChat(friend_list_OpenChatEvent);
            _emotion = new EmotionDropdown();

            to_Jid = jid;
            _connection = con;
            _nickname = jid.User;
            this.nikeName.Text = nickname;

            Util.GroupChatForms.Add(to_Jid.Bare.ToLower(), this);

            nikeName.Text = "当前所在会议室[" + _nickname + "]";

            _emotion.EmotionContainer.ItemClick += new UI.Face.EmotionItemMouseEventHandler(EmotionContainer_ItemClick);

            friendHead.BackgroundImage = ResClass.GetImgRes("Padding4Normal");
            friendHead.Image = ResClass.GetHead("big199");
        }
示例#3
0
        /// <summary>
        /// 更新消息显示
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="isSend"></param>
        public void RTBRecord_Show(CSS.IM.XMPP.protocol.client.Message msg, bool isSend)
        {
            System.Drawing.FontStyle fontStyle = new System.Drawing.FontStyle();
            System.Drawing.Font ft = null;

            #region 获取字体
            try
            {
                if (msg.GetTagBool("FBold"))
                {
                    fontStyle = System.Drawing.FontStyle.Bold;
                }
                if (msg.GetTagBool("FItalic"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Italic;
                }
                if (msg.GetTagBool("FStrikeout"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Strikeout;
                }
                if (msg.GetTagBool("FUnderline"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Underline;
                }
                ft = new System.Drawing.Font(msg.GetTag("FName"), float.Parse(msg.GetTag("FSize")), fontStyle);
            }
            catch (Exception)
            {
                ft = RTBRecord.Font;
            }
            #endregion

            #region 获取颜色
            Color cl = RTBRecord.ForeColor;
            try
            {
                byte[] cby = new byte[4];
                cby[0] = Byte.Parse(msg.GetTag("CA"));
                cby[1] = Byte.Parse(msg.GetTag("CR"));
                cby[2] = Byte.Parse(msg.GetTag("CG"));
                cby[3] = Byte.Parse(msg.GetTag("CB"));
                cl = Color.FromArgb(BitConverter.ToInt32(cby, 0));

            }
            catch
            {
                cl = RTBRecord.ForeColor;
            }
            #endregion

            int iniPos = this.RTBRecord.TextLength;//获得当前记录richBox中最后的位置
            String msgtext = msg.Body;
            //RTBRecord.Focus();
            RTBRecord.Select(RTBRecord.TextLength, 0);
            RTBRecord.ScrollToCaret();

            string face = "";

            try
            {
                face = msg.GetTag("face").ToString();
            }
            catch (Exception)
            {
                face = "";
            }

            if (face != "")//如果消息中有图片,则添加图片
            {
                string[] imagePos = face.Split('|');
                int addPos = 0;//
                int currPos = 0;//当前正要添加的文本位置
                int textPos = 0;
                for (int i = 0; i < imagePos.Length - 1; i++)
                {
                    string[] imageContent = imagePos[i].Split(',');//获得图片所在的位置、图片名称
                    currPos = Convert.ToInt32(imageContent[0]);//获得图片所在的位置

                    this.RTBRecord.AppendText(msgtext.Substring(textPos, currPos - addPos));
                    this.RTBRecord.SelectionStart = this.RTBRecord.TextLength;

                    textPos += currPos - addPos;
                    addPos += currPos - addPos;

                    Image image = null;

                    if (emotionDropdown == null)
                    {
                        emotionDropdown = new EmotionDropdown();
                    }

                    if (emotionDropdown.faces.ContainsKey(imageContent[1]))
                    {
                        if (this.RTBRecord.findPic(imageContent[1]) == null)
                            image = ResClass.GetImgRes("_" + int.Parse(imageContent[1].ToString()).ToString());
                        else
                            image = this.RTBRecord.findPic(imageContent[1]).Image;
                    }
                    else
                    {
                        String img_str = msg.GetTag(imageContent[1]);
                        try
                        {

                            if (msg.From.Bare == XmppConn.MyJID.Bare)
                            {
                                image = Image.FromFile(Util.sendImage + imageContent[1].ToString() + ".gif");
                            }
                            else
                            {
                                image = Image.FromFile(Util.receiveImage + imageContent[1].ToString() + ".gif");
                            }

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    this.RTBRecord.addGifControl(imageContent[1], image);
                    addPos++;
                }
                this.RTBRecord.AppendText(msgtext.Substring(textPos, msgtext.Length - textPos) + "  \n");
            }
            else
            {

                this.RTBRecord.AppendText(msgtext + "\n");
            }
            //RTBRecord.Focus();
            this.RTBRecord.Select(iniPos, this.RTBRecord.TextLength - iniPos);
            this.RTBRecord.SelectionFont = ft;
            this.RTBRecord.SelectionColor = cl;
            this.RTBRecord.Select(this.RTBRecord.TextLength, 0);
            this.RTBRecord.ScrollToCaret();
            //this.RTBRecord.Focus();
        }
示例#4
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            XmppConn = null;

            RTBRecord.Dispose();
            RTBRecord = null;

            if (删除记录ToolStripMenuItem!=null)
            {
                删除记录ToolStripMenuItem.Dispose();
                删除记录ToolStripMenuItem = null;
            }

            if (qqContextMenu1!=null)
            {
                qqContextMenu1.Dispose();
                qqContextMenu1 = null;
            }

            if (emotionDropdown!=null)
            {
                emotionDropdown.Dispose();
                emotionDropdown = null;
            }

            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
示例#5
0
        /// <summary>
        /// 更新消息显示
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="isSend"></param>
        public void RTBRecord_Show(CSS.IM.XMPP.protocol.client.Message msg, bool isSend)
        {
            string sqlstr = "insert into ChatMessageLog (Belong,Jid,[MessageLog],[DateNow])values ({0},{1},{2},{3})";
            sqlstr = String.Format(sqlstr,
                "'" + XmppConn.MyJID.Bare.ToString() + "'",
                "'" + (isSend == true ? msg.To.Bare.ToString() : msg.From.Bare.ToString()) + "'",
                "'" + msg.ToString() + "'",
                 "'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'");
            CSS.IM.Library.Data.OleDb.ExSQL(sqlstr);

            System.Drawing.FontStyle fontStyle = new System.Drawing.FontStyle();
            System.Drawing.Font ft = null;

            #region 获取字体
            try
            {
                if (msg.GetTagBool("FBold"))
                {
                    fontStyle = System.Drawing.FontStyle.Bold;
                }
                if (msg.GetTagBool("FItalic"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Italic;
                }
                if (msg.GetTagBool("FStrikeout"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Strikeout;
                }
                if (msg.GetTagBool("FUnderline"))
                {
                    fontStyle = fontStyle | System.Drawing.FontStyle.Underline;
                }
                ft = new System.Drawing.Font(msg.GetTag("FName"), float.Parse(msg.GetTag("FSize")), fontStyle);
            }
            catch (Exception)
            {
                ft = RTBRecord.Font;
            }
            #endregion

            #region 获取颜色
            Color cl = RTBRecord.ForeColor;
            try
            {
                byte[] cby = new byte[4];
                cby[0] = Byte.Parse(msg.GetTag("CA"));
                cby[1] = Byte.Parse(msg.GetTag("CR"));
                cby[2] = Byte.Parse(msg.GetTag("CG"));
                cby[3] = Byte.Parse(msg.GetTag("CB"));
                cl = Color.FromArgb(BitConverter.ToInt32(cby, 0));

            }
            catch
            {
                cl = RTBRecord.ForeColor;
            }
            #endregion

            int iniPos = this.RTBRecord.TextLength;//获得当前记录richBox中最后的位置
            String msgtext = msg.Body;
            RTBRecord.Select(RTBRecord.TextLength, 0);
            RTBRecord.ScrollToCaret();

            string face = "";
            try
            {
                if (msg.GetTag("face")!=null)
                {
                    face = msg.GetTag("face").ToString();
                }
                else
                {
                    face = "";
                }
            }
            catch (Exception)
            {

            }

            if (face != "")//如果消息中有图片,则添加图片
            {
                string[] imagePos = face.Split('|');
                int addPos = 0;//
                int currPos = 0;//当前正要添加的文本位置
                int textPos = 0;
                for (int i = 0; i < imagePos.Length - 1; i++)
                {
                    string[] imageContent = imagePos[i].Split(',');//获得图片所在的位置、图片名称
                    currPos = Convert.ToInt32(imageContent[0]);//获得图片所在的位置

                    this.RTBRecord.AppendText(msgtext.Substring(textPos, currPos - addPos));
                    this.RTBRecord.SelectionStart = this.RTBRecord.TextLength;

                    textPos += currPos - addPos;
                    addPos += currPos - addPos;

                    Image image = null;

                    if (emotionDropdown==null)
                    {
                        emotionDropdown = new EmotionDropdown();
                        emotionDropdown.EmotionContainer.ItemClick += new UI.Face.EmotionItemMouseEventHandler(EmotionContainer_ItemClick);
                    }

                    if (emotionDropdown.faces.ContainsKey(imageContent[1]))
                    {
                        if (this.RTBRecord.findPic(imageContent[1]) == null)
                            image = CSS.IM.UI.Util.ResClass.GetImgRes("_" + int.Parse(imageContent[1].ToString()).ToString());
                        else
                            image = this.RTBRecord.findPic(imageContent[1]).Image;

                        this.RTBRecord.addGifControl(imageContent[1], image);
                    }
                    else
                    {
                        try
                        {
                            if (isSend)
                            {
                                image = this.rtfSend.findPic(imageContent[1]).Image;
                                this.RTBRecord.addGifControl(imageContent[1], image);

                            }
                            else
                            {
                                image = CSS.IM.UI.Util.ResClass.GetImgRes("wite");
                                this.RTBRecord.addGifControl(imageContent[1] + "_r", image);
                            }

                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    addPos++;
                }
                this.RTBRecord.AppendText(msgtext.Substring(textPos, msgtext.Length - textPos) + "  \n");
            }
            else
            {
                this.RTBRecord.AppendText(msgtext + "\n");
            }

            this.RTBRecord.Select(iniPos, this.RTBRecord.TextLength - iniPos);
            this.RTBRecord.SelectionFont = ft;
            this.RTBRecord.SelectionColor = cl;
            this.RTBRecord.Select(this.RTBRecord.TextLength, 0);
            this.RTBRecord.ScrollToCaret();
        }
示例#6
0
 /// <summary>
 /// 选择表情事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btn_face_Click(object sender, EventArgs e)
 {
     if (emotionDropdown==null)
     {
         emotionDropdown = new EmotionDropdown();
         emotionDropdown.EmotionContainer.ItemClick+=new UI.Face.EmotionItemMouseEventHandler(EmotionContainer_ItemClick);
     }
     emotionDropdown.Show(btn_face);
 }
示例#7
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                if (avForm != null)
                {
                    avForm.AVClose();
                    avForm.Dispose();
                    avForm = null;
                }

            }
            catch (Exception)
            {

            }

            try
            {
                if (ravForm != null)
                {
                    ravForm.AVClose();
                    ravForm.Dispose();
                    ravForm = null;
                }
            }
            catch (Exception)
            {

            }

            try
            {
                sockUDP1.CloseSock();
                sockUDP1.Dispose();
                sockUDP1 = null;
            }
            catch (Exception)
            {

            }

            try
            {
                _emotion.Dispose();
                _emotion = null;
            }
            catch (Exception)
            {

            }

            try
            {
                Util.ChatForms.Remove(to_Jid.Bare.ToLower());
                _connection.MessageGrabber.Remove(to_Jid);
            }
            catch (Exception)
            {

            }

            g.Dispose();
            g = null;
            Bmp.Dispose();
            Bmp = null;

            _connection = null;

            System.GC.Collect();

            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }