⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formsendmsg.cs

📁 kuiMsg是一款用.net C# 开发的即时消息开源软件,适合.net即时消息软件开发者用。 主要功能: 支持文件传输(p2p); 支持GIF动画表情( 彻底消除闪屏 :) );
💻 CS
📖 第 1 页 / 共 4 页
字号:

            //显示tab控件
            this.tabCsendFile.SelectedTab = tabItem;
            this.exPanelFileTransfers.Visible = true;
            this.exPanelFileTransfers.Refresh();
        }

        void fSend_fileTransmitted(object sender, fileTransmitEvnetArgs e)
        {
            p2pFileTransmit FileSend = (sender as p2pFileTransmit);
            if (e.isSend)
                AppendSystemRtf("文件 " + e.fileName + " 已经传输完成!");
            else
                AppendSystemRtf("文件 " + e.fileName + " 已经传输完成,保存路径<file:\\\\" + e.fullFileName  + ">");

            delTabItem(FileSend);//删除文件传输Tab控件
        }

        void fSend_fileTransmitOutTime(object sender, fileTransmitEvnetArgs e)
        {
            p2pFileTransmit FileSend = (sender as p2pFileTransmit);
            if (e.isSend)
                AppendSystemRtf(" 文件发送超时 !");
            else
                AppendSystemRtf(" 文件接收超时!");
        }

        void fSend_fileTransmitError(object sender, fileTransmitEvnetArgs e)
        {
            //AppendSystemRtf(" 文件传输错误!" + e.errorMessage);
        }

        void fSend_fileTransmitCancel(object sender, fileTransmitEvnetArgs e)
        {
            p2pFileTransmit FileSend = (sender as p2pFileTransmit);
            if (e.isSend)
                AppendSystemRtf("您已经取消了文件 " + e.fileName + " 的传输!");
            else
                AppendSystemRtf("对方已经取消了文件 " + e.fileName + " 的传输!");

            delTabItem(FileSend);//删除文件传输Tab控件
        }

        void fSend_fileTransmitBefore(object sender, fileTransmitEvnetArgs e)
        {
            p2pFileTransmit FileSend = (sender as p2pFileTransmit);
            if (!e.isSend)
                AppendSystemRtf("您已经接收了文件 " + e.fileName + " 的传输,文件正在传输中...");
            else
                AppendSystemRtf("对方已经接收了文件 " + e.fileName + " 的传输,文件正在传输中...");
        }
         
        //#endregion

        //#region 文件发送取消、文件发送结束 事件

        private void AppendSystemRtf(string str)
        {
            IMLibrary.MyExtRichTextBox rich = new IMLibrary.MyExtRichTextBox();
            rich.AppendText("\n");
            rich.InsertImage((System.Drawing.Image)FormAccess.resourceManager.GetObject("security_infor"));
            rich.AppendText(" " + str);
            rich.ForeColor = Color.Brown;
            this.RTBRecord.AppendRtf(rich.Rtf);
            rich.Clear();
            rich.Dispose();
            this.RTBfocus();
        }

        private void delTabItem(p2pFileTransmit  FileSend)//删除文件传输Tab控件
        {
            try
            {
                DevComponents.DotNetBar.TabControlPanel tPanel = (FileSend.Parent as DevComponents.DotNetBar.TabControlPanel);
                tPanel.Text = "0";
                foreach (DevComponents.DotNetBar.TabItem tabItem in this.tabCsendFile.Tabs)
                    if ((tabItem.AttachedControl as DevComponents.DotNetBar.TabControlPanel).Text == "0")
                    {
                        this.tabCsendFile.Tabs.Remove(tabItem);
                        FileSend.Dispose();
                        tPanel.Dispose();
                        tabItem.Dispose();
                        this.tabCsendFile.Refresh();
                        break;
                    }
            }
            catch{}
        }

        private void tabCsendFile_TabRemoved(object sender, EventArgs e)
        {
            if (this.tabCsendFile.Tabs.Count == 0)
                this.exPanelFileTransfers.Visible = false;
        }
        #endregion

        # region 显示 对话历史 按钮事件
        private void butRecordshow_Click(object sender, System.EventArgs e)
        {
            string FormRecordMsgMisgTag = "FormRecordMsgMisg";
            Form f = FormAccess.findForm(FormRecordMsgMisgTag);
            if (f == null)
            {
                f = new FormRecordMsgMisg();
                f.Tag = FormRecordMsgMisgTag;
                FormAccess.sendMsgForms.add(f);
            }
            f.Show();
            f.Activate();
        }

        #endregion

        #region 将用户对话消息加入 RichTextBox 控件

        /// <summary>
        /// 将用户对话消息加入 RichTextBox 控件
        /// </summary>
        /// <param name="msg">消息类</param>
        /// <param name="IsSend">标记是发送消息还是收到消息</param>
        public void MsgToRichTextBox(IMLibrary.clientMsg msg, bool IsSend)//将发送的消息加入历史rich
        {
            IMLibrary.MyExtRichTextBox rich = new IMLibrary.MyExtRichTextBox();
            rich.ForeColor = Color.Red;
            rich.Font = new Font("宋体", 10);

            string title = FormAccess.selfInfo.userName + "(" + System.DateTime.Now.ToString() + ")";
            if (!IsSend)//如果是收到消息
            {
                this.currUserInfo = FormAccess.findUser(msg.sendUserId );
                if (this.currUserInfo != null)
                    title = this.currUserInfo.userName + "(" + System.DateTime.Now.ToString() + ")";
                rich.ForeColor = Color.Blue;
            }

            rich.AppendText(title);
            this.RTBRecord.AppendRtf(rich.Rtf);
            this.RTBRecord.AppendText("  ");

            int iniPos = this.RTBRecord.TextLength;//获得当前记录richBox中最后的位置
            rich.Clear();
            rich.Dispose();

            if (msg.imageInfo != "")//如果消息中有图片,则添加图片
            {
                string[] imagePos = msg.imageInfo.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(msg.msgContent.Substring(textPos, currPos - addPos));
                    this.RTBRecord.SelectionStart = this.RTBRecord.TextLength;

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

                    IMLibrary.MyPicture pic;
 
                    if (Convert.ToUInt32(imageContent[1]) < 201)//如果发送的图片是自带的,则已知尺寸, 96
                    {
                        pic = this.addGifControl(imageContent[1],"_" + imageContent[1]);
                    }
                    else
                    {
                        if (IsSend)//如果图片是自己发送给自己的
                        {
                            pic  = this.findPic(imageContent[1], this.SendGifs); 
                        }
                        else//如果图片是对方发送给自己的
                        {
                            pic = new IMLibrary.MyPicture();
                            pic = this.addGifControl("wait", "wait"); 
                            pic.Tag = imageContent[1];
                            pic.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
                            this.ArrivalGifs.add(pic);
                        }
                    }

                    pic.BackColor = this.RTBRecord.BackColor;

                    this.RTBRecord.InsertMyControl(pic);

                    addPos++;
                }
                this.RTBRecord.AppendText(msg.msgContent.Substring(textPos, msg.msgContent.Length - textPos) + " \n");
            }
            else//如果消息中没有图片,则直接添加消息文本
            {
                this.RTBRecord.AppendText(msg.msgContent + "\n");
            }

            this.RTBfocus();

            if (!IsSend)
            {
                this.currUserInfo = FormAccess.findUser(this.Tag.ToString());
                if (this.currUserInfo != null)
                {
                    IMLibrary.clientMsg Msg = new IMLibrary.clientMsg();
                    FormAccess.sendMsgToOneUser(11, Msg, this.currUserInfo);//告诉发消息的联系人已经收到发送的消息
                    System.Threading.Thread.Sleep(20);
                    FormAccess.sendMsgToOneUser(11, Msg, this.currUserInfo);//告诉发消息的联系人已经收到发送的消息
                }
                dataAccess.addMsgToDB(msg.msgContent, msg.sendUserId, FormAccess.selfInfo.UserID, msg.Version.ToString(), System.DateTime.Now.ToString(), msg.imageInfo, true);//将消息添加进数据库
            }


        }
        #endregion

        #region 获得发送的消息类
        /// <summary>
        /// 获得发送的消息类
        /// </summary>
        /// <returns></returns>
        private IMLibrary.clientMsg GetSendMsg()//获得要发送的消息类
        {
            IMLibrary.clientMsg Msg = new IMLibrary.clientMsg();
            IMLibrary.MyExtRichTextBox rich = new IMLibrary.MyExtRichTextBox();
            rich.Rtf = this.RTBSend.Rtf;
            Msg.msgContent = rich.Text;//获得消息内容
            Msg.fontName = this.RTBSend.Font.Name;//获得文本字体
            Msg.fontColor = this.RTBSend.ForeColor.ToArgb();//获得文本颜色
            Msg.fontBold = this.RTBSend.Font.Bold;//获得文本精细

            IMLibrary.REOBJECT reObject = new IMLibrary.REOBJECT();
            IMLibrary.MyPicture pic;

            for (int i = 0; i < this.RTBSend.GetRichEditOleInterface().GetObjectCount(); i++)
            {
                this.RTBSend.GetRichEditOleInterface().GetObject(i, reObject, IMLibrary.GETOBJECTOPTIONS.REO_GETOBJ_ALL_INTERFACES);
                pic = this.findPic(reObject.dwUser.ToString(), this.SendGifs);
                if (pic != null)
                {
                    pic.IsSent = true;//发送此图片
                    Msg.imageInfo += reObject.cp.ToString() + "," + reObject.dwUser.ToString() + "," + pic.Image.Size.Width.ToString() + "," + pic.Image.Size.Height.ToString() + "|";
                }
                else
                {
                    Msg.imageInfo += reObject.cp.ToString() + "," + reObject.dwUser.ToString() + "|";
                }
            }
            rich.Clear();
            rich.Dispose();
            return Msg;
        }

        #endregion

        #region 在Gifs中查找图片控件
        private IMLibrary.MyPicture findPic(string ID, IMLibrary.gifCollections  gifs)
        {
            foreach (IMLibrary.MyPicture pic in gifs)
                if (Convert.ToString(pic.Tag) == ID)
                    return pic;
            return null;
        }
        #endregion

        #region 屏幕截图
        private void butCapture_Click(object sender, System.EventArgs e)
        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -