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

📄 grichtextboxex.cs

📁 语音视频功能 里面实现了基本的QQ与语音对话
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace gowk.forms
{
	/// <summary>
	/// GRichTextBoxEX 的摘要说明。
	/// </summary>
	public class GRichTextBoxEX : gowk.controls.GPanel
	{
		public event SendMessageEventHandler SendMessage;
		private gowk.controls.GPanel gPanel1;
		private gowk.controls.GButton btncapture;
		private gowk.controls.GButton btninsertimage;
		private gowk.controls.GButton btnshortcup;
		private gowk.controls.GButton btnfont;
		private gowk.controls.GButton btnemotion;
		private gowk.controls.GButton btnscene;
		private gowk.controls.GButton btnsms;
		private gowk.controls.GButton btnbackgroud;
		private gowk.controls.GPanel gPanel2;
		private gowk.controls.GRichTextBox r;
		private gowk.controls.GButton btnsend;
		private gowk.controls.GButton btnexpand;
		private gowk.controls.GImage gImage1;
		private gowk.controls.GToolTip gToolTip1;
		/// <summary> 
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public GRichTextBoxEX()
		{
			// 该调用是 Windows.Forms 窗体设计器所必需的。
			this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);
			InitializeComponent();
			this.btnsend.Anchor=AnchorStyles.None;
			this.r.KeyUp+=new KeyEventHandler(r_KeyUp);
		//	this.gPanel1.BackColor=Color.FromArgb(128,Color.White);
			gowk.common.SkinConfig.Instance.SkinChanged+=new EventHandler(Instance_SkinChanged);
			this.InitialSkin();

		}
		private void InitialSkin()
		{
			gowk.common.SkinConfig skn=gowk.common.SkinConfig.Instance;
		btncapture.BackgroundImage=skn.GetImage("/gowk_skin/images/xTextBox/capture");
		btninsertimage.BackgroundImage=skn.GetImage("/gowk_skin/images/xTextBox/insert");
		btnshortcup.BackgroundImage=skn.GetImage("/gowk_skin/images/xTextBox/shortcup");
		btnfont.BackgroundImage=skn.GetImage("/gowk_skin/images/xTextBox/font");
		btnemotion.BackgroundImage=skn.GetImage("/gowk_skin/images/xTextBox/emotion");
		btnscene.BackgroundImage=skn.GetImage("/gowk_skin/images/xTextBox/scene");
		btnsms.BackgroundImage=skn.GetImage("/gowk_skin/images/xTextBox/sms");
		btnbackgroud.BackgroundImage=skn.GetImage("/gowk_skin/images/xTextBox/background");
		btnsend.BackgroundImage=skn.GetImage("/gowk_skin/images/xTextBox/send");
		}

		private void Instance_SkinChanged(object sender, EventArgs e)
		{
			this.InitialSkin();
		}
		/// <summary> 
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region 组件设计器生成的代码
		/// <summary> 
		/// 设计器支持所需的方法 - 不要使用代码编辑器 
		/// 修改此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(GRichTextBoxEX));
			this.gPanel1 = new gowk.controls.GPanel();
			this.btnexpand = new gowk.controls.GButton();
			this.btnbackgroud = new gowk.controls.GButton();
			this.btnsms = new gowk.controls.GButton();
			this.btnscene = new gowk.controls.GButton();
			this.btncapture = new gowk.controls.GButton();
			this.btninsertimage = new gowk.controls.GButton();
			this.btnshortcup = new gowk.controls.GButton();
			this.btnfont = new gowk.controls.GButton();
			this.btnemotion = new gowk.controls.GButton();
			this.gPanel2 = new gowk.controls.GPanel();
			this.btnsend = new gowk.controls.GButton();
			this.gImage1 = new gowk.controls.GImage();
			this.r = new gowk.controls.GRichTextBox();
			this.gToolTip1 = new gowk.controls.GToolTip();
			this.gPanel1.SuspendLayout();
			this.gPanel2.SuspendLayout();
			this.SuspendLayout();
			// 
			// gPanel1
			// 
			this.gPanel1.BackColor = System.Drawing.Color.Transparent;
			this.gPanel1.Controls.Add(this.btnexpand);
			this.gPanel1.Controls.Add(this.btnbackgroud);
			this.gPanel1.Controls.Add(this.btnsms);
			this.gPanel1.Controls.Add(this.btnscene);
			this.gPanel1.Controls.Add(this.btncapture);
			this.gPanel1.Controls.Add(this.btninsertimage);
			this.gPanel1.Controls.Add(this.btnshortcup);
			this.gPanel1.Controls.Add(this.btnfont);
			this.gPanel1.Controls.Add(this.btnemotion);
			this.gPanel1.Dock = System.Windows.Forms.DockStyle.Top;
			this.gPanel1.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.gPanel1.IsRound = false;
			this.gPanel1.Location = new System.Drawing.Point(0, 0);
			this.gPanel1.Name = "gPanel1";
			this.gPanel1.Size = new System.Drawing.Size(320, 26);
			this.gPanel1.TabIndex = 0;
			// 
			// btnexpand
			// 
			this.btnexpand.Anchor = System.Windows.Forms.AnchorStyles.Left;
			this.btnexpand.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.btnexpand.IsRound = true;
			this.btnexpand.Location = new System.Drawing.Point(288, 3);
			this.btnexpand.Name = "btnexpand";
			this.btnexpand.Size = new System.Drawing.Size(20, 20);
			this.btnexpand.TabIndex = 9;
			this.gToolTip1.SetToolTip(this.btnexpand, "展开");
			this.btnexpand.Click += new System.EventHandler(this.btnexpand_Click);
			// 
			// btnbackgroud
			// 
			this.btnbackgroud.Anchor = System.Windows.Forms.AnchorStyles.Left;
			this.btnbackgroud.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.btnbackgroud.IsRound = true;
			this.btnbackgroud.Location = new System.Drawing.Point(168, 3);
			this.btnbackgroud.Name = "btnbackgroud";
			this.btnbackgroud.Size = new System.Drawing.Size(20, 20);
			this.btnbackgroud.TabIndex = 8;
			this.gToolTip1.SetToolTip(this.btnbackgroud, "背景");
			// 
			// btnsms
			// 
			this.btnsms.Anchor = System.Windows.Forms.AnchorStyles.Left;
			this.btnsms.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.btnsms.IsRound = true;
			this.btnsms.Location = new System.Drawing.Point(192, 3);
			this.btnsms.Name = "btnsms";
			this.btnsms.Size = new System.Drawing.Size(20, 20);
			this.btnsms.TabIndex = 7;
			this.gToolTip1.SetToolTip(this.btnsms, "短信");
			// 
			// btnscene
			// 
			this.btnscene.Anchor = System.Windows.Forms.AnchorStyles.Left;
			this.btnscene.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.btnscene.IsRound = true;
			this.btnscene.Location = new System.Drawing.Point(136, 3);
			this.btnscene.Name = "btnscene";
			this.btnscene.Size = new System.Drawing.Size(20, 20);
			this.btnscene.TabIndex = 6;
			this.gToolTip1.SetToolTip(this.btnscene, "场景");
			// 
			// btncapture
			// 
			this.btncapture.Anchor = System.Windows.Forms.AnchorStyles.Left;
			this.btncapture.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.btncapture.IsRound = true;
			this.btncapture.Location = new System.Drawing.Point(112, 3);
			this.btncapture.Name = "btncapture";
			this.btncapture.Size = new System.Drawing.Size(20, 20);
			this.btncapture.TabIndex = 5;
			this.gToolTip1.SetToolTip(this.btncapture, "捕捉屏幕");
			this.btncapture.Click += new System.EventHandler(this.btncapture_Click);
			// 
			// btninsertimage
			// 
			this.btninsertimage.Anchor = System.Windows.Forms.AnchorStyles.Left;
			this.btninsertimage.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.btninsertimage.IsRound = true;
			this.btninsertimage.Location = new System.Drawing.Point(88, 3);
			this.btninsertimage.Name = "btninsertimage";
			this.btninsertimage.Size = new System.Drawing.Size(20, 20);
			this.btninsertimage.TabIndex = 3;
			this.gToolTip1.SetToolTip(this.btninsertimage, "插入图片");
			this.btninsertimage.Click += new System.EventHandler(this.btninsertimage_Click);
			// 
			// btnshortcup
			// 
			this.btnshortcup.Anchor = System.Windows.Forms.AnchorStyles.Left;
			this.btnshortcup.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.btnshortcup.IsRound = true;
			this.btnshortcup.Location = new System.Drawing.Point(56, 3);
			this.btnshortcup.Name = "btnshortcup";
			this.btnshortcup.Size = new System.Drawing.Size(20, 20);
			this.btnshortcup.TabIndex = 1;
			this.gToolTip1.SetToolTip(this.btnshortcup, "快捷回复");
			// 
			// btnfont
			// 
			this.btnfont.Anchor = System.Windows.Forms.AnchorStyles.Left;
			this.btnfont.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.btnfont.IsRound = true;
			this.btnfont.Location = new System.Drawing.Point(8, 3);
			this.btnfont.Name = "btnfont";
			this.btnfont.Size = new System.Drawing.Size(20, 20);
			this.btnfont.TabIndex = 0;
			this.gToolTip1.SetToolTip(this.btnfont, "字体");
			this.btnfont.Click += new System.EventHandler(this.btnfont_Click);
			// 
			// btnemotion
			// 
			this.btnemotion.Anchor = System.Windows.Forms.AnchorStyles.Left;
			this.btnemotion.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.btnemotion.IsRound = true;
			this.btnemotion.Location = new System.Drawing.Point(32, 3);
			this.btnemotion.Name = "btnemotion";
			this.btnemotion.Size = new System.Drawing.Size(20, 20);
			this.btnemotion.TabIndex = 1;
			this.gToolTip1.SetToolTip(this.btnemotion, "表情");
			this.btnemotion.Click += new System.EventHandler(this.btnemotion_Click);
			// 
			// gPanel2
			// 
			this.gPanel2.BackColor = System.Drawing.Color.Transparent;
			this.gPanel2.Controls.Add(this.btnsend);
			this.gPanel2.Dock = System.Windows.Forms.DockStyle.Right;
			this.gPanel2.GBorderStyle = gowk.controls.GBorderStyle.Null;
			this.gPanel2.IsRound = false;
			this.gPanel2.Location = new System.Drawing.Point(256, 26);
			this.gPanel2.Name = "gPanel2";
			this.gPanel2.Size = new System.Drawing.Size(64, 70);
			this.gPanel2.TabIndex = 1;
			// 
			// btnsend
			// 
			this.btnsend.GBorderStyle = gowk.controls.GBorderStyle.Solid;
			this.btnsend.GImage = this.gImage1;
			this.btnsend.IsRound = true;
			this.btnsend.Location = new System.Drawing.Point(12, 15);
			this.btnsend.Name = "btnsend";
			this.btnsend.Size = new System.Drawing.Size(40, 40);
			this.btnsend.TabIndex = 1;
			this.btnsend.Click += new System.EventHandler(this.btnsend_Click);
			// 
			// gImage1
			// 
			this.gImage1.ActiveImage = ((System.Drawing.Image)(resources.GetObject("gImage1.ActiveImage")));
			this.gImage1.Image = null;
			this.gImage1.NormalImage = ((System.Drawing.Image)(resources.GetObject("gImage1.NormalImage")));
			this.gImage1.PressedImage = ((System.Drawing.Image)(resources.GetObject("gImage1.PressedImage")));
			// 
			// r
			// 
			this.r.BackColor = System.Drawing.Color.Transparent;
			this.r.BorderStyle = System.Windows.Forms.BorderStyle.None;
			this.r.Dock = System.Windows.Forms.DockStyle.Fill;
			this.r.HiglightColor = Khendys.Controls.RtfColor.White;
			this.r.Location = new System.Drawing.Point(0, 26);
			this.r.Name = "r";
			this.r.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.None;
			this.r.Size = new System.Drawing.Size(256, 70);
			this.r.TabIndex = 2;
			this.r.Text = "";
			this.r.TextColor = Khendys.Controls.RtfColor.Black;
			this.r.KeyDown += new System.Windows.Forms.KeyEventHandler(this.r_KeyDown);
			// 
			// gToolTip1
			// 
			this.gToolTip1.BackColor = System.Drawing.Color.Empty;
			this.gToolTip1.Icon = null;
			this.gToolTip1.MaxTipWidth = 0;
			// 
			// GRichTextBoxEX
			// 
			this.BackColor = System.Drawing.SystemColors.Control;
			this.Controls.Add(this.r);
			this.Controls.Add(this.gPanel2);
			this.Controls.Add(this.gPanel1);
			this.Name = "GRichTextBoxEX";
			this.Size = new System.Drawing.Size(320, 96);
			this.gPanel1.ResumeLayout(false);
			this.gPanel2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnfont_Click(object sender, System.EventArgs e)
		{
			FontDialog fd= new FontDialog();
			fd.ShowColor=true;
			if(fd.ShowDialog(this.FindForm())==DialogResult.OK)
			{
				this.r.SelectionColor=fd.Color;
				this.r.SelectionFont=fd.Font;
			}

		}

		private void btnemotion_Click(object sender, System.EventArgs e)
		{
			EmotionForm ef=new EmotionForm();
			ef.TopMost=true;
			ef.Location=this.PointToScreen(new Point(this.btnemotion.Right,this.btnemotion.Bottom));
			System.Windows.Forms.DialogResult dr=ef.ShowDialog(this.FindForm());
			ef.Show();
			if(ef.Emotion!=null && ef.Emotion.Image!=null)
			{
				try
				{
					this.r.InsertImage(ef.Emotion.Path);
				}
				catch(System.Exception ex)
				{
					gowk.utility.Diagnostics.Debug.Write(ex);
					MessageBox.Show(ex.Message);
				}
			}
			ef.Dispose();
		}

		private void r_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
		}
		private void InvokeSendMessage()
		{
			if(this.r.Text==null ||this.r.Text==string.Empty)
			{
				this.r.Notify("输入内容不能为空!");
				return;
			}
			if(this.SendMessage!=null)this.SendMessage(this,new SendMessageEventArgs(this.r.Text,this.r.Rtf));
			Font f=this.r.SelectionFont;
			Color c=this.r.SelectionColor;
			this.r.Clear();
			this.r.SelectionColor=c;
			this.r.SelectionFont=f;
		}

		private void btnsend_Click(object sender, System.EventArgs e)
		{
			this.InvokeSendMessage();
		}

		private void btninsertimage_Click(object sender, System.EventArgs e)
		{
			System.Windows.Forms.OpenFileDialog of=new OpenFileDialog();
			of.Filter=@"*.gif/*.bmp/*.jpg/*.png|*.gif;*.bmp;*.jpg;*.png|所有文件|*.*";
			if(of.ShowDialog()==DialogResult.OK)
			{
				try
				{
					this.r.InsertImage(of.FileName);
				}
				catch(System.Exception ex)
				{
					gowk.utility.Diagnostics.Debug.Write(ex);
					MessageBox.Show(ex.Message);
				}
			}
		}

		private void btncapture_Click(object sender, System.EventArgs e)
		{
			CaptureForm cf=new CaptureForm();
			cf.ShowDialog();
			if(cf.Image!=null)
			{
				this.r.InsertImage(cf.Image);
			}
		}

		private void btnexpand_Click(object sender, System.EventArgs e)
		{
		
		}
		public void Notify(string msg)
		{
			this.r.Notify(msg);
		}
	
		public gowk.controls.GRichTextBox GRichTextBox
		{
			get{return this.r;}
		}
		public class SendMessageEventArgs:System.EventArgs
		{
			public string Text,Rtf;
			public SendMessageEventArgs(string txt,string rtf)
			{
				this.Text=txt;this.Rtf=rtf;
			}
		}
		public delegate void SendMessageEventHandler(object sender,SendMessageEventArgs se);

		private void r_KeyUp(object sender, KeyEventArgs e)
		{
			if(e.Control && e.KeyCode==System.Windows.Forms.Keys.Enter)
			{
				this.r.Text=this.r.Text.TrimEnd('\n');
				this.InvokeSendMessage();
			}
		}
	}
}

⌨️ 快捷键说明

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