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

📄 gform.cs

📁 语音视频功能 里面实现了基本的QQ与语音对话
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;

using gowk.common;

namespace gowk.controls
{

	public class GForm : System.Windows.Forms.Form
	{
		Color transparencyKey=Color.Empty;
		
		bool captionBar=false,showborder=false,sysMenu=true;
		public bool CaptionBar
		{
			get{return this.captionBar;}
			set
			{
				if(this.captionBar!=value)
				{
					this.captionBar=value;this.UpdateStyles();
				}
			}
		}
		public bool ShowBorder
		{
			get{return this.showborder;}
			set
			{
				if(this.showborder!=value)
				{
					this.showborder=value;this.UpdateStyles();
				}
			}
		}
		public bool SysMenu
		{
			get{return this.sysMenu;}
			set
			{
				if(this.sysMenu!=value)
				{
					this.sysMenu=value;this.UpdateStyles();
				}
			}
		}
		protected override void OnLocationChanged(EventArgs e)
		{
			base.OnLocationChanged (e);
			this.sizing=false;
		}

		public void MoveWindow()
		{
			Message m=new Message();
			m.HWnd=this.Handle;
			m.Msg=API.WM_SYSCOMMAND;
			m.WParam=new IntPtr(API.SC_MOVE|API.HTCAPTION);
			base.WndProc(ref m);
		}

		public void ResizeWindow(int x,int y)
		{
			Rectangle rect=this.ClientRectangle;
			int ht=0;

			int b=10;
			if(x-rect.X<b)
			{
				if(y-rect.Top<b)
				{
				//	ht=API.HTTOPLEFT;
					ht=4;
				}
				else if(rect.Bottom-y<b)
				{
				//	ht=API.HTBOTTOMLEFT;
					ht=7;
				}
				else
				{
					//	ht=API.HTLEFT;
					ht=1;
				}
			}
			else if(rect.Right-x<b)
			{
				if(y-rect.Top<b)
				{
					//		ht=API.HTTOPRIGHT;
					ht=5;
				}
				else if(rect.Bottom-y<b)
				{
					//	ht=API.HTBOTTOMRIGHT;
					ht=8;
				}
				else
				{
						ht=2;
					//	ht=API.HTTOP;
				}
			}
			else
			{
				if(y-rect.Top<b)
				{
					//ht=API.HTRIGHT;
					ht=11;
				}
				else 
				{
				//	ht=API.HTBOTTOM;
					ht=6;
				}
			}
			Message m=new Message();
			m.HWnd=this.Handle;
			m.Msg=API.WM_SYSCOMMAND;
			m.LParam=gowk.common.Util.MAKELPARAM(Control.MousePosition.X,Control.MousePosition.Y);
			m.WParam=new IntPtr(API.SC_SIZE|ht);
				this.WndProc(ref m);
		}

	
		public GForm()
		{
			this.SetStyle(
				ControlStyles.ResizeRedraw|
				ControlStyles.UserPaint
				|ControlStyles.SupportsTransparentBackColor
	//			|ControlStyles.AllPaintingInWmPaint
				|ControlStyles.DoubleBuffer,
				true);
			this.FormBorderStyle=FormBorderStyle.None;
			this.isRound=true;
			if(this.ShellCreateBackgroundImage)this.CreateAndSetBackgroundImage();
		}
	/*	public new Color TransparencyKey
		{
			get
			{
				return base.TransparencyKey;
			}
			set
			{
				base.TransparencyKey=Color.FromArgb(value.A,value.R,value.G,value.B);
			}
		}*/

		/*
		private  void DrawFrame()
		{
			IntPtr hdc;
			Graphics dstg,tmpg;
			if(this.bitmap!=null)this.bitmap.Dispose();
			this.bitmap=new Bitmap(this.Width,this.Height);
			try
			{
				hdc=API.GetWindowDC(this.Handle);
				dstg=Graphics.FromHdc(hdc);
			}
			catch
			{
				return;
			}

			tmpg=Graphics.FromImage(this.bitmap);
			if((this.BackgroundImage!=null) &&(this.TransparencyKey!=Color.Empty))
			{
				RectangleF rectF=this.Region.GetBounds(tmpg);
				tmpg.DrawImage(this.BackgroundImage,rectF);
			}
			else
			{
				this.DrawBackGround(tmpg);
				this.DrawBorder(tmpg);
			}
			dstg.ExcludeClip(this.GetClient());

			dstg.DrawImage(this.bitmap,this.GetVirtualRectangle());
			//dstg.FillRectangle(new SolidBrush(Color.Blue),this.GetClient());

			tmpg.Dispose();
			dstg.Dispose();

			API.ReleaseDC(this.Handle,hdc);
		}*/
		private void DrawBorder(Graphics g)
		{
			if(this.gBorderStyle==GBorderStyle.Null)return;
			Color color=(this.gBorderStyle==GBorderStyle.Null)?System.Windows.Forms.ControlPaint.Light(this.BackColor):this.BorderColor;
		//	g.FillRectangle(new SolidBrush(Color.Red),this.GetVirtualRectangle());
			Pen p=new Pen(System.Windows.Forms.ControlPaint.Light(color));
			switch(this.GBorderStyle)
			{
				case GBorderStyle.Dash:
					p.DashStyle=System.Drawing.Drawing2D.DashStyle.Dash;
					break;
				case GBorderStyle.Dot:
					p.DashStyle=System.Drawing.Drawing2D.DashStyle.Dot;
					break;
				case GBorderStyle.DashDot:
					p.DashStyle=System.Drawing.Drawing2D.DashStyle.DashDot;
					break;
				case GBorderStyle.DashDotDot:
					p.DashStyle=System.Drawing.Drawing2D.DashStyle.DashDotDot;
					break;
				default:
					p.DashStyle=System.Drawing.Drawing2D.DashStyle.Solid;
					break;
			}
			Rectangle rect=this.ClientRectangle;
			rect.Width-=1;
			rect.Height-=1;
			if(this.isRound)
			{
				g.DrawPath(p,GetPath(rect));
			}
			else
				g.DrawRectangle(p,rect);
		}
		protected virtual void DrawBackGround(Graphics g)
		{
		//	g.FillRectangle(new SolidBrush(this.BackColor),this.GetVirtualRectangle());
			/*                              this.Bounds.Width;
			 * A------B-------------C---------D-----------
			 *                                |a   V
			 * frameW |   clientW   | frameW  |   capAndFrameH
			 *                                |    V
			 * --------------------------------------------
			 *                                |b   V
			 *        |             |         |    
			 *                                |    V
			 * -------------------------------------------
			 *                                |c   V
			 *        |             |         |    bottomHeiht
			 *                                |    V
			 * ------------------------------------------
			 *                                |d
			*/
		/*	g.FillRectangle(new SolidBrush(this.BackColor),0,0,this.Width,this.Height);
			Rectangle client=this.ClientRectangle;
			int bottomHeight=30;
			int frameW=client.X;
			int clientW=client.Width;
			int clientH=client.Height;
			int capAndFrameH=client.Y;*/
		//	System.Diagnostics.Debug.Assert(this.ShellCreateBackgroundImage);
		int topHeight=this.ImageTopLeft.Height;
			int bottomHeight=this.ImageBottomLeft.Height;
			int middleHeight=this.Height-topHeight-bottomHeight;
			Rectangle top1=new Rectangle(0,0,this.ImageTopLeft.Width,topHeight);
			Rectangle top2=new Rectangle(top1.Right,top1.Top,this.Width-top1.Width-this.ImageTopRight.Width,topHeight);
			Rectangle top3=new Rectangle(top2.Right,top1.Top,this.ImageTopRight.Width,topHeight);

			Rectangle m1=new Rectangle(top1.Left,top1.Bottom,this.ImageMiddleLeft.Width,middleHeight);
			Rectangle m2=new Rectangle(m1.Right,top1.Bottom,this.Width-m1.Width-this.ImageMiddleRight.Width,middleHeight);
			Rectangle m3=new Rectangle(m2.Right,top1.Bottom,this.ImageMiddleRight.Width,middleHeight);

			Rectangle b1=new Rectangle(top1.Left,m1.Bottom,this.ImageBottomLeft.Width,bottomHeight);
			Rectangle b2=new Rectangle(b1.Right,m1.Bottom,this.Width-b1.Width-this.ImageBottomRight.Width,bottomHeight);
			Rectangle b3=new Rectangle(b2.Right,m1.Bottom,this.ImageBottomRight.Width,bottomHeight);
/*			if(this.ImageTopLeft ==null ||this.ImageBottomLeft==null)return;
			int W=this.Width;
			int H=this.Height;
			int 
			int A=0;
			int B=XX;
			int C=W-XX;
			int D=W;
			int a=0;
			int b=XX;
			int c=H-XX;
			int d=H;

			
			if(this.ImageTopLeft!=null)     UT.DrawImage(g,this.ImageTopLeft,     new Rectangle(A,a,B-A,b-a),StretchOption.Null);
			if(this.ImageTopCenter!=null)   UT.DrawImage(g,this.ImageTopCenter,   new Rectangle(B,a,C-B,b-a),this.stretchOption);
			if(this.ImageTopRight!=null)    UT.DrawImage(g,this.ImageTopRight,    new Rectangle(C,a,D-C,b-a),StretchOption.Null);

			if(this.ImageMiddleLeft!=null)  UT.DrawImage(g,this.ImageMiddleLeft,  new Rectangle(A,b,B-A,c-b),StretchOption.Null);
			if(this.ImageMiddleCenter!=null)UT.DrawImage(g,this.ImageMiddleCenter,new Rectangle(B,b,C-B,c-b),this.stretchOption);
			if(this.ImageMiddleRight!=null) UT.DrawImage(g,this.ImageMiddleRight, new Rectangle(C,b,D-C,c-b),StretchOption.Null);
			
			if(this.ImageBottomLeft!=null)  UT.DrawImage(g,this.ImageBottomLeft,  new Rectangle(A,c,B-A,d-c),StretchOption.Null);
			if(this.ImageBottomCenter!=null)UT.DrawImage(g,this.ImageBottomCenter,new Rectangle(B,c,C-B,d-c),this.stretchOption);
			if(this.ImageBottomRight!=null) UT.DrawImage(g,this.ImageBottomRight, new Rectangle(C,c,D-C,d-c),StretchOption.Null);
		//	g.FillRectangle(new SolidBrush(Color.Red),new Rectangle(0,0,D,d));
		*/
			
			if(this.ImageTopLeft!=null)     UT.DrawImage(g,this.ImageTopLeft,     top1,StretchOption.Null);
			if(this.ImageTopCenter!=null)   UT.DrawImage(g,this.ImageTopCenter,   top2,StretchOption.HRepeat);
			if(this.ImageTopRight!=null)    UT.DrawImage(g,this.ImageTopRight,    top3,StretchOption.Null);

			if(this.ImageMiddleLeft!=null)  UT.DrawImage(g,this.ImageMiddleLeft,  m1,StretchOption.VRepeat);
			if(this.ImageMiddleCenter!=null)UT.DrawImage(g,this.ImageMiddleCenter,m2,StretchOption.Repeat);
			if(this.ImageMiddleRight!=null) UT.DrawImage(g,this.ImageMiddleRight, m3,StretchOption.VRepeat);
			
			if(this.ImageBottomLeft!=null)  UT.DrawImage(g,this.ImageBottomLeft,  b1,StretchOption.Null);
			if(this.ImageBottomCenter!=null)UT.DrawImage(g,this.ImageBottomCenter,b2,StretchOption.HRepeat);
			if(this.ImageBottomRight!=null) UT.DrawImage(g,this.ImageBottomRight, b3,StretchOption.Null);
		}

		#region new member
	/*	public new Color TransparencyKey
		{
			get{return base.TransparencyKey;}
			set
			{
				if(base.TransparencyKey!=value)
				{
					base.TransparencyKey=value;
					this.SetRegion();
				}
			}
		}*/

		#endregion
		#region utility
	/*	private Rectangle GetClient()
		{
			int x=this.showborder?SystemInformation.FrameBorderSize.Width:0;
			int y=this.showborder?SystemInformation.FrameBorderSize.Height:0;
			y+=this.CaptionBar?SystemInformation.CaptionHeight:0;
			return new Rectangle(
				x,
				y,
				this.ClientRectangle.Width-1,
				this.ClientRectangle.Height-1);
		}*/

		protected virtual void SetRegion()
		{return;
			if(!this.isRound)return;
			if(this.TransparencyKey!=Color.Empty && this.BackgroundImage!=null && !this.ShellCreateBackgroundImage)
			{
				this.Region=UT.BitmapToRegion(new Bitmap(this.BackgroundImage),this.TransparencyKey);
			}
			else if(isRound && !this.ShellCreateBackgroundImage)
			{
				this.Region=new Region(this.GetPath(this.GetVirtualRectangle()));
			}
		//	else
		///	{
		///		this.Region=new Region(this.GetVirtualRectangle());
		//	}
		}
		protected GraphicsPath GetPath(Rectangle rect)
		{
			GraphicsPath gp;
			if(this.Width>80 && this.Height>60)
				gp=UT.CreateLargeRoundGraphicsPath(rect);
			else
				gp=UT.CreateSmallRoundGraphicsPath(rect);
			return gp;
		}
		protected Rectangle GetVirtualRectangle()
		{
			return new Rectangle(0,0,Width,Height);
		}
		private Point GetMousePosition()
		{
			return this.PointToClient(Control.MousePosition);
		}

		#endregion

		#region IGControl 成员
			
		int XXX=8;
		private StretchOption stretchOption;
		public StretchOption StretchOption
		{
			get	
			{
				return this.stretchOption;
			}
			set	
			{
				this.stretchOption=value;
			}
		}


		bool isRound;
		Color borderColor=Color.Gold;
		GBorderStyle gBorderStyle=GBorderStyle.Null;

		public Color BorderColor
		{
			get{return this.borderColor;}
			set{
				this.borderColor=value;this.Invalidate();}
		}
		public bool IsRound
		{
			get{return this.isRound;}
			set
			{
				if(this.isRound==value)return;
				this.isRound=value;
				this.SetRegion();
			}
		}
		public GBorderStyle GBorderStyle
		{
			get{return this.gBorderStyle;}
			set{this.gBorderStyle=value;this.Invalidate();}
		}

		private Image imageTopLeft;
		private Image imageTopCenter;
		private Image imageTopRight;
		private Image imageMiddleLeft;
		private Image imageMiddleCenter;
		private Image imageMiddleRight;
		private Image imageBottomLeft;
		private Image imageBottomCenter;
		private Image imageBottomRight;
		public Image ImageTopLeft
		{
			get	
			{
				return this.imageTopLeft;
			}
			set	
			{
				this.imageTopLeft=value;
				if(this.ImageTopLeft!=null)this.DockPadding.Top=this.ImageTopLeft.Height;//-8;
			}
		}
		public Image ImageTopCenter
		{
			get	
			{
				return this.imageTopCenter;
			}
			set	
			{
				this.imageTopCenter=value;
			}
		}
		public Image ImageTopRight
		{
			get	
			{
				return this.imageTopRight;
			}
			set	
			{
				this.imageTopRight=value;
			}
		}
		public Image ImageMiddleLeft
		{
			get	
			{
				return this.imageMiddleLeft;
			}
			set	
			{
				this.imageMiddleLeft=value;
				if(this.ImageMiddleLeft!=null)this.DockPadding.Left=this.ImageMiddleLeft.Width;//-XXX;
			}
		}
		public Image ImageMiddleCenter
		{
			get	
			{
				return this.imageMiddleCenter;
			}
			set	
			{
				this.imageMiddleCenter=value;
			}
		}
		public Image ImageMiddleRight
		{
			get	
			{
				return this.imageMiddleRight;
			}
			set	
			{
				this.imageMiddleRight=value;
				if(this.imageMiddleRight!=null)this.DockPadding.Right=this.imageMiddleRight.Width;//-XXX;
			}
		}
		public Image ImageBottomLeft
		{
			get	
			{
				return this.imageBottomLeft;
			}
			set	
			{
				this.imageBottomLeft=value;
				if(this.imageBottomLeft!=null)this.DockPadding.Bottom=this.imageBottomLeft.Height;//-XXX;
			}
		}
		public Image ImageBottomCenter
		{
			get	
			{
				return this.imageBottomCenter;

⌨️ 快捷键说明

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