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

📄 formsendmsg.cs

📁 kuiMsg是一款用.net C# 开发的即时消息开源软件,适合.net即时消息软件开发者用。 主要功能: 支持文件传输(p2p); 支持GIF动画表情( 彻底消除闪屏 :) );
💻 CS
📖 第 1 页 / 共 4 页
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IMLibrary;
namespace LanMsg 
{
    public partial class FormSendMsg : DevComponents.DotNetBar.Office2007Form //Form
    {
  
        #region 用户变量
        /// <summary>
        /// 消息发送超时计数器
        /// </summary>
        private int OutTime = 0;
        /// <summary>
        /// 当前对话用户
        /// </summary>
        private exUser currUserInfo=new exUser(); 

        /// <summary>
        /// 当前发送的消息
        /// </summary>
        private IMLibrary.clientMsg SendTextMsg=new IMLibrary.clientMsg();

        /// <summary>
        /// 当前要发送的自定义图片集合
        /// </summary>
        private IMLibrary.gifCollections  SendGifs = new gifCollections();

        /// <summary>
        ///  当前收到的自定义图片集合
        /// </summary>
        private IMLibrary.gifCollections ArrivalGifs = new gifCollections();

        /// <summary>
        /// 系统表情集合
        /// </summary>
        private IMLibrary.gifCollections faceGifs = new gifCollections();

        #endregion

        #region 初始化窗口及事件
        public FormSendMsg()
        {
            InitializeComponent();
            this.RTBRecord.LinkClicked += new LinkClickedEventHandler(RTBRecord_LinkClicked);
            this.RTBSend.LinkClicked += new LinkClickedEventHandler(RTBRecord_LinkClicked);
            this.RTBSend.KeyDown +=new KeyEventHandler(RTBSend_KeyDown);
            this.RTBRecord.TextChanged +=new EventHandler(RTBRecord_TextChanged);
            this.ButAV.Click +=new EventHandler(ButAV_Click);
            this.myAV1.AVCancel +=new MyAV.AVCancelEventHandler(myAV1_AVCancel);
            this.myAV1.AVReceve +=new MyAV.AVReceveEventHandler(myAV1_AVReceve);
            this.butCapture.Click +=new EventHandler(butCapture_Click);
            this.butClose.Click +=new EventHandler(butClose_Click);
            this.butEnterSend.Click +=new EventHandler(butEnterSend_Click);
            this.butEnterCtrlSend.Click += new EventHandler(butEnterSend_Click);
            this.butFontColor.Click +=new EventHandler(butFontColor_Click);
            this.butRecordshow.Click +=new EventHandler(butRecordshow_Click);
            this.butSend.Click +=new EventHandler(butSend_Click);
            this.butSendFile.Click +=new EventHandler(butSendFile_Click);
            this.butSendPicture.Click +=new EventHandler(butSendPicture_Click);
            this.timerCheckSendIsSuccess.Tick +=new EventHandler(timerCheckSendIsSuccess_Tick);
            this.RTBSend.KeyDown +=new KeyEventHandler(RTBSend_KeyDown); 
            this.Load +=new EventHandler(FormSendMsg_Load);
            this.FormClosing += new FormClosingEventHandler(FormSendMsg_Closing);
            this.RTBRecord.DragEnter += new DragEventHandler(richTextBox_DragEnter);
            this.RTBRecord.DragDrop += new DragEventHandler(richTextBox_DragDrop);
            this.RTBSend.DragEnter += new DragEventHandler(richTextBox_DragEnter);
            this.RTBSend.DragDrop += new DragEventHandler(richTextBox_DragDrop);
            this.RTBSend.AllowDrop = true;
            this.RTBRecord.AllowDrop = true;

            ///设置发送消息快捷键
            if (FormAccess.settings.IsEnterKeySendMsg)
                this.butEnterSend.Checked = true;
            else
                this.butEnterCtrlSend.Checked = true;
        }
        #endregion 

        #region richTextBox拖操作
        private void richTextBox_DragEnter(object sender,System.Windows.Forms.DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Text))
                e.Effect = DragDropEffects.All;


            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                e.Effect = DragDropEffects.All;
            }
             
        }

        private void richTextBox_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {

            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {

                currUserInfo = FormAccess.findUser(this.Tag.ToString());
                if (currUserInfo == null) return;

                string[] MyFiles;
                int i;

                // 将文件赋给一个数组。

                MyFiles = (string[])(e.Data.GetData(DataFormats.FileDrop));
                // 循环处理数组并将文件添加到列表中。

                for (i = 0; i <= MyFiles.Length - 1; i++)
                {
                    System.IO.FileInfo f = new System.IO.FileInfo(MyFiles[i]);

                    if (f.Exists)
                        this.FileTransfers(true, f.Name, f.FullName, f.Extension, f.Length, currUserInfo.IP, currUserInfo.Port);
                }
            }

            else if (e.Data.GetDataPresent(DataFormats.Text) && this.RTBSend.SelectedText != "")
                e.Effect = DragDropEffects.Move;
            else if (e.Data.GetDataPresent(DataFormats.Text) && this.RTBSend.SelectedText == "")
                e.Effect = DragDropEffects.Copy;
            else
                this.Text = e.Data.GetType().Name;

        }
        #endregion

        #region 窗体加载、窗体关闭、关闭按钮、字体、颜色按钮事件
        private void FormSendMsg_Load(object sender, System.EventArgs e)
        {
            IniFace();
            this.RTBSend.Focus();
            this.RTBSend.Select();
        }

        private void butClose_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void trtFontSet_Click(object sender, System.EventArgs e)
        {
            System.Windows.Forms.FontDialog fd = new FontDialog();
            if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                this.RTBSend.Font = fd.Font;
        }

        private void butFontColor_Click(object sender, System.EventArgs e)
        {
            System.Windows.Forms.ColorDialog cd = new ColorDialog();
            if (cd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                this.RTBSend.ForeColor = cd.Color;
        }

        private void FormSendMsg_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (this.tabCsendFile.Tabs.Count > 0)
                if (MessageBox.Show("您还有" + this.tabCsendFile.Tabs.Count.ToString() + "个文件在传输任务中,确定要关闭对话框并终止文件传输吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.No)
                    e.Cancel = true;
            if (!this.ButAV.Enabled)
                if (MessageBox.Show("您正在写对方进行视频对话,确定退出视频对话吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.No)
                    e.Cancel = true;
                else
                {
                   this.currUserInfo = FormAccess.findUser (this.Tag.ToString());
                   if (this.currUserInfo != null)
                       FormAccess.sendMsgToOneUser(22, new IMLibrary.clientMsg(), this.currUserInfo);//告诉对方已经取消了视频对话
                }
        }
        #endregion

        #region 发送图片 按钮事件
        private void butSendPicture_Click(object sender, System.EventArgs e)
        {
            System.Windows.Forms.OpenFileDialog fd = new OpenFileDialog();
            fd.Filter = "图像文件|*.*;*.jpg;*.jpeg;*.gif;*.ico";
            if (fd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                System.IO.FileInfo fInfo = new System.IO.FileInfo(fd.FileName);
                if (fInfo.Length / (1024 * 70) > 0)
                {
                    MessageBox.Show("当前版本不支持发送大于70K的图片,请使用发送文件功能来发送。", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    //LanMsg.MyPicture pic =new MyPicture ();
                    //pic.SizeMode=System.Windows.Forms.PictureBoxSizeMode.AutoSize;
                    //pic.BackColor=this.RTBSend.BackColor;
                    //pic.Image=System.Drawing.Image.FromFile(fd.FileName);
                    //System.Random R=new Random();
                    //pic.Tag=R.Next(200,2147483627);
                    //System.IO.DirectoryInfo dInfo=new System.IO.DirectoryInfo(Application.StartupPath +"\\sendImage");
                    //if(!dInfo.Exists)
                    //    dInfo.Create();
                    //pic.Image.Save(Application.StartupPath +"\\sendImage\\"+ pic.Tag.ToString() +".gif",System.Drawing.Imaging.ImageFormat.Gif );
                    //this.RTBSend.InsertMyControl(pic);
                    //System.Drawing.ImageAnimator.Animate(pic.Image,new System.EventHandler(this.OnFrameChanged));
                    //this.SendGifs.add(pic);
                }
            }
        }
        #endregion

        #region 发送消息 菜单事件
        private void butEnterSend_Click(object sender, System.EventArgs e)
        {
            DevComponents.DotNetBar.ButtonItem but=  sender as DevComponents.DotNetBar.ButtonItem;
            if(but==null)return;
            this.butEnterSend.Checked = false;
            this.butEnterCtrlSend.Checked = false;
            but.Checked=true;
            FormAccess.settings.IsEnterKeySendMsg = this.butEnterSend.Checked;
        }

        int sendCount = 0;///记录按键次数,只能发送一次数据
        private void RTBSend_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            sendCount++;
            if (sendCount >= 2)
            {
                  sendCount = 0;
                  return;
            }
            if (this.butEnterSend.Checked && e.KeyCode == System.Windows.Forms.Keys.Enter)
                this.butSend_Click(null, null);
            else if (this.butEnterCtrlSend.Checked && e.Control && e.KeyCode == System.Windows.Forms.Keys.Enter)
                this.butSend_Click(null, null);
        }

        #endregion

        #region 发送消息 按钮事件 与启用或禁用发送按钮函数
        private void butSend_Click(object sender, System.EventArgs e)
        {
            if (this.RTBSend.Text == "")
            {
                MessageBox.Show("不能发送空消息。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            this.currUserInfo = FormAccess.findUser(this.Tag.ToString());

            if (this.currUserInfo != null)
            {
                currUserInfo.SendIsSuccess = false;//假设消息发送不成功

                this.SendTextMsg = this.GetSendMsg();
                FormAccess.sendMsgToOneUser(10, this.SendTextMsg, this.currUserInfo);
                EnBut(false);//禁用发送功能
            }
            else
            {
                MessageBox.Show("用户不存在,发送失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }

        private void EnBut(bool t)//启用或禁用发送功能
        {

⌨️ 快捷键说明

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