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

📄 glistview.cs

📁 语音视频功能 里面实现了基本的QQ与语音对话
💻 CS
📖 第 1 页 / 共 2 页
字号:
					return folder.GetItemAtPoint(p);
				}
			}
			return null;
		}
		private GListViewFolder GetItemFolder(GListViewItem item)
		{
			if(item is GListViewFolder)
				return (GListViewFolder)item;
			else
			{
				return GetItemFolder(item.Parent);
			}
		}

		#endregion

		protected internal virtual void OnDrawItem(GListViewDrawItemEventArgs e)
		{
	//		System.Diagnostics.Trace.WriteLine("ondrawitem");
			if(this.DrawItem!=null)
			{
				this.DrawItem(this,e);
				if(e.Drawed)return;
			}
			if(e.Bounds.Width<=0 ||e.Bounds.Height<=0)return;

			GListViewItem item=e.Item;
			Graphics g=e.Graphics;
			State state=State.Normal;
			Rectangle rect=e.Bounds;
			Image img=null;
			Image backGoundImage=null;
			Color foreColor;
			Rectangle imgRect,strRect;
			
			if(rect.Contains(this.GetMousePosition()))
			{
				state=this.Capture?State.Pressed:State.Actived;
			}
			img=item.GImage.GetImageByState(state);
			foreColor=this.GColor.GetColorByState(state);
			backGoundImage=item.BackGroundImage.GetImageByState(state);
			this.GetRectangle(rect,item,out imgRect,out strRect);

			//draw backGoundImge
			if(backGoundImage!=null)g.DrawImage(backGoundImage,rect);
			else if(item is GListViewFolder)
			{
				ButtonState bs;
				switch(state)
				{
					case State.Actived:
						bs=ButtonState.Flat;
						break;
					case State.Pressed:
						bs=ButtonState.Pushed;
						break;
					default:
						bs=ButtonState.Normal;
						break;

				}
				System.Windows.Forms.ControlPaint.DrawButton(g,rect,bs);
			}
			if(img!=null)g.DrawImage(img,imgRect);
			StringFormat sf=new StringFormat();
			sf.Trimming=StringTrimming.Character;
			sf.LineAlignment=StringAlignment.Center;
			sf.Alignment=(item.Parent!=null && item.Parent.View==View.SmallIcon)?StringAlignment.Near:StringAlignment.Center;
			g.DrawString(item.Text,this.Font,new SolidBrush(foreColor),strRect,sf);
		}
		public void GetRectangle(Rectangle rect,GListViewItem item,out Rectangle imgRect,out Rectangle strRect)
		{
			int smallImageHeight=18;
			int largeImageHeight=38;
			imgRect=rect;
			strRect=new Rectangle();
			if(item.Parent==null)
			{
				imgRect.Inflate(-2,(int)((smallImageHeight-rect.Height)/2));
				imgRect.Width=smallImageHeight;
			//	imgRect.Inflate(-5,-5);
			//	strRect.X=imgRect.Right+2;
				strRect.X=rect.X;
				strRect.Y=rect.Y+(int)((smallImageHeight-this.Font.Height)/2);
				strRect.Height=this.Font.Height;
				strRect.Width=rect.Right-strRect.Left;
			}
			else if(item.Parent.View!=View.LargeIcon)
			{
				imgRect.Inflate(-2,(int)((smallImageHeight-rect.Height)/2));
				imgRect.Width=smallImageHeight;
				strRect.X=imgRect.Right+2;
				strRect.Y=rect.Y+(int)((smallImageHeight-this.Font.Height)/2);
				strRect.Height=this.Font.Height;
				strRect.Width=rect.Right-strRect.Left;
			}
			else
			{
				imgRect.Inflate((int)((largeImageHeight-rect.Width)/2),0);
				imgRect.Y=(int)((rect.Height-largeImageHeight-this.Font.Height-2)/2)+rect.Y;
				imgRect.Height=largeImageHeight;
				imgRect.Width=largeImageHeight;
			//	imgRect.Inflate(-2,-2);
				strRect.X=rect.Left;
				strRect.Y=imgRect.Bottom+1;
				strRect.Height=this.Font.Height;
				strRect.Width=rect.Width;
			}
		}

		#region
		private void Dispatch()
		{
			int expanded_item_height=this.InnerHeight-(this.Items.Count-1)*this.minimize_height;
			int x=this.border_left+this.left_offset;
			int y=this.border_top+this.top_offset;
			int w=this.InnerWidth;

			if(expanded_item_height>=this.minimize_height)
			{
				foreach(GListViewFolder item in items)
				{
					if(item==this.items[this.expandfolderindex])
					{
						item.Rect=new Rectangle(x,y,w,expanded_item_height);
						y+=expanded_item_height;
					}
					else
					{
						item.Rect=new Rectangle(x,y,w,this.minimize_height);
						y+=this.minimize_height;
					}
				}
			}
			else
			{
				int left=this.InnerHeight;
				foreach(GListViewFolder item in this.Items)
				{
					if(left>0)
					{
						int curItemHeight=(left>=this.minimize_height)?this.minimize_height:left;
						item.Rect=new Rectangle(x,y,w,curItemHeight);
						y+=curItemHeight;
						left-=curItemHeight;
					}
					else
					{
						item.Rect=Rectangle.Empty;
					}
				}
			}
			
		/*	foreach(GListViewFolder item in items)
			{
				System.Diagnostics.Trace.WriteLine("dispach"+item.Text+":"+item.Rect.ToString());
			}*/
		}

		public void BeginUpdate()
		{
			this.isInitialing=true;
		}
		public void EndUpdate()
		{
			this.isInitialing=false;
			this.update();
		}
		private void update()
		{
			if(this.isInitialing)return;
			this.Dispatch();
			foreach(GListViewFolder folder in this.Items)folder.Update();
			this.Invalidate();
		}

		#endregion

		private class GListViewFolderManager
		{
			private GListView glistView;
			private GListViewFolder m_old,m_new;
			private Timer timer;
			private int cnt;
			public GListViewFolderManager(GListView glistView)
			{
				this.cnt=0;
				this.glistView=glistView;
				this.timer=new Timer();
				this.timer.Interval=20;
				this.timer.Enabled=false;
				this.timer.Tick+=new EventHandler(timer_Tick);
				this.glistView.ItemExpanded+=new ItemEventHandler(glistView_ItemExpanded);
			}
			private void glistView_ItemExpanded(object sender, ItemEventArgs e)
			{
				if(this.m_new==null)this.m_new=this.glistView.GetExpandedFolder();
				GListViewFolder tmp=e.Item as GListViewFolder;
				if(tmp==null || this.m_new==tmp)
				{
					return;
				}
		/*		else if(this.m_new==null)
				{
					this.m_new=tmp;
					this.m_old=null;
				}*/
				else
				{
					this.m_new.expanded=false;
					this.m_old=this.m_new;
					this.m_new=tmp;
				//	int max=this.glistView.InnerHeight-this.glistView.Items.Count*this.glistView.MinItemHeight;
					this.cnt=5;
					this.timer.Enabled=true;
				}
			}
			private void timer_Tick(object sender, EventArgs e)
			{
				if(this.cnt<=1)
				{
					this.timer.Enabled=false;
					this.glistView.update();
					return;
				}
				int change=(int)((this.m_old.Rect.Height-this.glistView.MinItemHeight)/cnt);
				int x=this.glistView.border_left+this.glistView.left_offset;
				int y=this.glistView.border_top+this.glistView.top_offset;
				int w=this.glistView.InnerWidth;
				foreach(GListViewFolder item in this.glistView.Items)
				{
					int h=item.Rect.Height;
					if(item==this.m_old)
					{
						h-=change;
					}
					else if(item==this.m_new)
					{
						h+=change;
					}
					item.Rect=new Rectangle(x,y,w,h);
					y+=h;
				}
				foreach(GListViewFolder folder in this.glistView.Items)
				{
					folder.Update();
				}
			//	this.glistView.Invalidate();

				this.cnt-=1;
			}
		}
		[Serializable,Editor( typeof( GListViewItemCollectionEditor ), typeof( UITypeEditor ) )]
		public class GListViewFolderCollection:GListViewItemCollection
		{
			public GListViewFolderCollection(GListView gListView):base(gListView)
			{
			}
		}
	}
	public delegate void ItemEventHandler(object sender,ItemEventArgs e);
	public delegate void DrawItemEventHandler(object sender,GListViewDrawItemEventArgs e);
	public class ItemEventArgs:System.EventArgs
	{
		GListViewItem item;
		public ItemEventArgs(GListViewItem item):base()
		{
			this.item=item;
		}
		public GListViewItem Item
		{
			get{return this.item;}
		}
	}

	public class GListViewDrawItemEventArgs
	{
		Graphics graphics;
		Rectangle rect;
		GListViewItem item;
		State state;
		bool ownerDrawed;
		public GListViewDrawItemEventArgs(Graphics graphics,Rectangle rect,GListViewItem item ,State state)
		{
			this.graphics=graphics;
			this.rect=rect;
			this.item=item;
			this.state=state;
		}
		public Rectangle Bounds
		{
			get
			{
				return this.rect;
			}
		}
 
		public State State
		{
			get
			{
				return this.state;
			}
		}
		public Graphics Graphics
		{
			get
			{
				return this.graphics;
			}
		}
		public GListViewItem Item
		{
			get
			{
				return this.item;
			}
		}
		public bool Drawed
		{
			get{return this.ownerDrawed;}
			set{this.ownerDrawed=value;}
		}
	}
}

⌨️ 快捷键说明

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