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

📄 formsendmsg.cs

📁 该即时通讯系统系统能够实现像QQ一样的通讯功能
💻 CS
📖 第 1 页 / 共 5 页
字号:
			this.Controls.Add(this.panel10);
			this.Controls.Add(this.splitter1);
			this.Controls.Add(this.panelSend);
			this.Controls.Add(this.panel5);
			this.Controls.Add(this.panelAV);
			this.Controls.Add(this.panelRiht);
			this.Controls.Add(this.panelRightNotice);
			this.Controls.Add(this.panel2);
			this.Controls.Add(this.bar1);
			this.Controls.Add(this.ribbonControl1);
			this.Controls.Add(this.barLeftDockSite);
			this.Controls.Add(this.barRightDockSite);
			this.Controls.Add(this.barTopDockSite);
			this.Controls.Add(this.barBottomDockSite);
			this.DockPadding.Bottom = 2;
			this.DockPadding.Left = 2;
			this.DockPadding.Right = 2;
			this.DockPadding.Top = 2;
			this.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MinimumSize = new System.Drawing.Size(530, 440);
			this.Name = "FormSendMsg";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "与某某对话";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.FormSendMsg_Closing);
			this.Load += new System.EventHandler(this.FormSendMsg_Load);
			((System.ComponentModel.ISupportInitialize)(this.bar1)).EndInit();
			this.panelRightNotice.ResumeLayout(false);
			this.panelAVchat.ResumeLayout(false);
			this.panelSendAndNotice.ResumeLayout(false);
			this.panel14.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.bar4)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tabCsendFile)).EndInit();
			this.panelSend.ResumeLayout(false);
			this.panelEx2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.bar2)).EndInit();
			this.panelButSend.ResumeLayout(false);
			this.panel8.ResumeLayout(false);
			this.panel9.ResumeLayout(false);
			this.panel10.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.bar3)).EndInit();
			this.panelSendFile.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		#region 窗体加载、窗体关闭、关闭按钮、字体、颜色按钮事件
		private void FormSendMsg_Load(object sender, System.EventArgs e)
		{
			IniFace();
		}
		
		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.ButAVchat.Enabled)
				if(MessageBox.Show("您正在写对方进行视频对话,确定退出视频对话吗?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Information)==System.Windows.Forms.DialogResult.No)
					e.Cancel=true;
				else
				{
					LanMsg.ClassUserInfo userinfo =this.FormMain.formMain.findUser(this.Tag.ToString());
					if(userinfo!=null)
						this.FormMain.formMain.sendMsgToOneUser(new LanMsg.Controls.ClassMsg(15,"",null),userinfo.IP,userinfo.Port);
				}

		}
		#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)
		{
			this.butEnterSend.Checked=true;
			this.butEnterCtrlSend.Checked=!this.butEnterSend.Checked;
		}
		private void butEnterCtrlSend_Click(object sender, System.EventArgs e)
		{
			this.butEnterSend.Checked=false;
			this.butEnterCtrlSend.Checked=!this.butEnterSend.Checked;
		}
		private void RTBSend_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			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=="")
			{
				balloonTip1.SetBalloonCaption(this.RTBSend ,"提示");   
				balloonTip1.SetBalloonText(this.RTBSend,"不能发送空消息。");
				balloonTip1.ShowBalloon(this.RTBSend);
				//MessageBox.Show("不能发送空消息。","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
				return;
			}
 			currUserInfo=this.FormMain.formMain.findUser(this.Tag.ToString());
			if(currUserInfo!=null)
			{
				EnBut(false);//禁用发送功能
				currUserInfo.SendIsSuccess=false;//假设消息发送不成功
//				LanMsg.Controls.ClassMsg msg=new LanMsg.Controls.ClassMsg(5,"", System.Text.Encoding.Unicode.GetBytes(this.RTBSend.Rtf));

				LanMsg.Controls.ClassMsg msg=new LanMsg.Controls.ClassMsg(12,"",GetSendString());

				FormMain.formMain.sendMsgToOneUser(msg,currUserInfo.IP,currUserInfo.Port );
			}
		}
 
		private void EnBut(bool t)//启用或禁用发送功能
		{
			this.butSend.Enabled=t;
			this.RTBSend.ReadOnly=!t;
			OutTime=0;
			this.timerCheckSendIsSuccess.Enabled=!t;//开始检测消息是否发送成功
		}

		#endregion 

        #region 获得要发送的 文本消息 序列化后的字节数据
		private byte[] GetSendString()//获得要发送的序列化字串
		{
            this.SendTextMsg=GetSendTextMsg();
			return ( new LanMsg.ClassSerializers().SerializeBinary(this.SendTextMsg).ToArray()); 
		}
		#endregion 

		#region 检查 消息是否发送成功 timer事件
		private void timerCheckSendIsSuccess_Tick(object sender, System.EventArgs e)
		{   
			if(currUserInfo!=null)
			{
				OutTime++;
				if(OutTime==50 && !currUserInfo.SendIsSuccess)//如果消息没有发送成功
				{
					balloonTip1.SetBalloonCaption(this.butSend,"提示");   
					balloonTip1.SetBalloonText(this.butSend,"消息发送不成功(原因可能是对方已经脱机或要发送的消息数据量太大以及其它网络故障)。");
					balloonTip1.ShowBalloon(this.butSend);
					//MessageBox.Show("消息发送不成功(原因可能是对方已经脱机或网络出现故障)。","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
					EnBut(true);//启用发送功能
					this.RTBSend.Focus();
				}
				string title="";
				if(currUserInfo.SendIsSuccess)//如果消息发送成功 
				{
					if(this.RTBSend.Text!="")
					this.FormMain.formMain.MsgAddToDB(this.SendTextMsg.MsgContent,this.FormMain.formMain.selfInfo.ID,currUserInfo.ID,this.FormMain.formMain.selfInfo.AssemblyVersion,System.DateTime.Now.ToString(),this.SendTextMsg.ImageInfo,true);//将消息添加进数据库
				    title=this.FormMain.formMain.selfInfo.UserName  +"("+ System.DateTime.Now.ToString() +")";
//					this.newMsg(this.RTBSend.Rtf,title,new System.Drawing.Font("宋体",10),Color.Red);
                    this.newTextMsg(title,new System.Drawing.Font("宋体",10),Color.Red);
					this.sendSelfImage();//发送附加的自定义图片
					this.RTBSend.Clear();
					EnBut(true);//启用发送功能
				}
			}
		}
		#endregion

		#region //发送自定义的图片文件
		private void sendSelfImage()//发送图片文件
		{
			foreach(LanMsg.MyPicture pic in this.SendGifs)
			{
				if(pic.IsSent)
				{
				    currUserInfo=this.FormMain.formMain.findUser(this.Tag.ToString());
					if(currUserInfo!=null)
					{
						LanMsg.ClassSendImage sImage=new ClassSendImage();//要发送的图片文件类
						sImage.ID=Convert.ToUInt32(pic.Tag);
						sImage.Image=Image.FromFile(Application.StartupPath +"\\sendImage\\"+ pic.Tag.ToString() +".gif");

						LanMsg.Controls.ClassMsg msg=new LanMsg.Controls.ClassMsg(11,"",new ClassSerializers().SerializeBinary(sImage).ToArray());
						FormMain.formMain.sendMsgToOneUser(msg,currUserInfo.IP,currUserInfo.Port);
						System.Threading.Thread.Sleep(500);
					}
				}
			}
			this.SendGifs.Clear();
		}
		#endregion

		#region RichBox 关联 菜单事件
		private void dotNetBarManager1_ItemClick(object sender, System.EventArgs e)
		{
			switch((sender as DevComponents.DotNetBar.ButtonItem ).Name )
			{
				case "复制"	:
					if(this.RTBRecord.Focus())
						this.RTBRecord.Copy (); 
					if(this.RTBSend.Focus())
						this.RTBSend.Copy (); 
					break;
				case "粘贴"	:
					if(this.RTBRecord.Focus())
					{   }
					if(this.RTBSend.Focus())
						this.RTBSend.Paste (); 
					break;
				case "全选"	:
					if(this.RTBRecord.Focus())
						this.RTBRecord.SelectAll (); 
					if(this.RTBSend.Focus())
						this.RTBSend.SelectAll (); 
					break;
				case "剪切"	:
					if(this.RTBRecord.Focus())
					{} 
					if(this.RTBSend.Focus())
						this.RTBSend.Cut (); 
					break;

			}
		}

		#endregion

		#region RichBox 超链接 单击事件
		private void RTBRecord_LinkClicked(object sender, LinkClickedEventArgs e)
		{
			try
			{
				System.Diagnostics.Process.Start(e.LinkText);
			}
			catch 
			{
				//MessageBox.Show("无法打开链接。","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
			}
		}
		#endregion

		#region 历史richbox 文本改变后 事件
		private void RTBRecord_TextChanged(object sender, System.EventArgs e)
		{
			this.RTBRecord.Focus();
			this.RTBRecord.Select(this.RTBRecord.Text.Length-1,0);
			this.RTBSend.Focus();
		}
		#endregion

		#region 打开共享 按钮单击事件
		private void butOpenShared_Click(object sender, System.EventArgs e)
		{
			try
			{
				string sharedComputerName="\\\\"+ Convert.ToString(this.Tag);
				System.Diagnostics.Process.Start(sharedComputerName);
			}
			catch  
			{
				MessageBox.Show("无法打开对方("+ Convert.ToString(this.Tag) +")的共享文件夹(原因可能是对方没有开机或没有设置共享以及其它网络故障造成的)。","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);

⌨️ 快捷键说明

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