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

📄 glistviewfolder.cs

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

namespace gowk.controls
{
	[Serializable]
	public class GListViewFolder:GListViewItem
	{
		Rectangle rect;
		GScrollBar m_GScrollBar;
		int m_TotalHeight;//no include the folderhead
		ArrayList m_VisableItems;
		public GListViewFolder():base()
		{
			this.m_VisableItems=new ArrayList();
			this.m_GScrollBar=new GScrollBar();
			this.m_GScrollBar.Visible=false;
			this.m_GScrollBar.ValueChanged+=new EventHandler(m_GScrollBar_ValueChanged);
			this.m_GScrollBar.Orientation=Orientation.Vertical;
			this.m_GScrollBar.Width=15;
		}
		[System.ComponentModel.Browsable(false),System.ComponentModel.DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public GScrollBar GScrollBar
		{
			get{return this.m_GScrollBar;}
		}
		public Rectangle Rect
		{
			get{return this.rect;}
			set{this.rect=value;}
		}
		private void SettingScroolBarArguments()
		{
			this.m_GScrollBar.Top=this.Rect.Top+this.GListView.MinItemHeight;
			this.m_GScrollBar.Left=this.Rect.Right-this.m_GScrollBar.Width;
			this.m_GScrollBar.Height=this.Rect.Height-this.GListView.MinItemHeight;
			int sc=this.GListView.MinItemHeight;
			int lc=this.Rect.Height-this.GListView.MinItemHeight;
			lc=lc>sc?lc:sc;
			this.m_GScrollBar.Minimum=0;
			this.m_GScrollBar.LargeChange=lc;
			this.m_GScrollBar.Maximum=this.m_TotalHeight;
			this.m_GScrollBar.SmallChange=sc;
			this.m_GScrollBar.Visible=(this.m_GScrollBar.Maximum>this.Rect.Height-this.GListView.MinItemHeight)&& (this.Rect.Height>this.GListView.MinItemHeight);
			if(!this.m_GScrollBar.Visible)this.m_GScrollBar.Value=0;
			if(!this.GListView.Controls.Contains(this.m_GScrollBar))
				this.GListView.Controls.Add(this.m_GScrollBar);
		}
		private void ChangeVisableItems()
		{
			this.m_VisableItems.Clear();
			this.AddItem2VisableItems(this);
		}
		private void AddItem2VisableItems(GListViewItem item)
		{
			foreach(GListViewItem itm in item.Items)
			{
				if(itm.Visible)
				{
					this.m_VisableItems.Add(itm);
					if(itm.Expanded)this.AddItem2VisableItems(itm);
				}
			}
		}

		private void SetTotalHeight()
		{
			int h=0;
			foreach(GListViewItem item in this.m_VisableItems)
			{
				h+=this.GetItemHeight(item);
			}
			this.m_TotalHeight=h;
		}
			
		private int GetItemHeight(GListViewItem item)
		{
			return item.parent.View==View.LargeIcon?this.GListView.MaxItemHeight:this.GListView.MinItemHeight;
		}


		internal void Invalidate()
		{
			this.Paint(this.GListView.CreateGraphics());
		}
		internal void Paint(Graphics g)
		{
			int x=this.Rect.X;
			int w=this.Rect.Width;
			int start=this.Rect.Y+this.GListView.MinItemHeight;//可以开始画的位置
			int y=start-this.m_GScrollBar.Value;//子项中的第一个项的y偏移
			int end=this.rect.Bottom;


			g.SetClip(this.Rect);
			Rectangle hr=this.Rect;
			if(hr.Height>this.GListView.MinItemHeight)
			{
				hr.Height=this.GListView.MinItemHeight;
				this.GListView.OnDrawItem(new GListViewDrawItemEventArgs(g,hr,this,State.Normal));
			}
			else
			{
				hr.Height=this.GListView.MinItemHeight;
				this.GListView.OnDrawItem(new GListViewDrawItemEventArgs(g,hr,this,State.Normal));
				return;
			}
			hr=new Rectangle(x,start,w,this.Rect.Height-this.GListView.MinItemHeight);
			g.SetClip(hr);
			if(this.m_GScrollBar.Visible)w-=this.m_GScrollBar.Width;
			foreach(GListViewItem item in this.m_VisableItems)
			{
				if(y>=end)
					break;
				int h=this.GetItemHeight(item);
				if(y>-h)
				{
					int indent=this.GetLevel(item)*this.GListView.Indent;
					Rectangle r=new Rectangle(x+indent,y,w-indent,h);
					
					GListViewDrawItemEventArgs e=new GListViewDrawItemEventArgs(g,r,item,State.Normal);
					this.GListView.OnDrawItem(e);
					
				}
				y+=h;
			}
			g.ResetClip();
		}
		private int GetLevel(GListViewItem item)
		{
			return item.Parent==null?0:1+GetLevel(item.Parent);
		}
		private bool IsItemVisable(GListViewItem item)
		{
			return this.m_VisableItems.IndexOf(item)!=-1;
		}
		internal Rectangle GetItemRectangle(GListViewItem item)
		{
			if(item==this)
			{
				Rectangle hr=this.Rect;
			//	if(hr.Height>this.GListView.MinItemHeight)
					hr.Height=this.GListView.MinItemHeight;
				return hr;
			}

			if(!this.IsItemVisable(item))return Rectangle.Empty;

			
			int x=this.Rect.X;
			int w=this.m_GScrollBar.Visible?(this.Rect.Width-this.m_GScrollBar.Width):this.Rect.Width;
			int start=this.Rect.Y+this.GListView.MinItemHeight;//可以开始画的位置
			int y=start-this.m_GScrollBar.Value;//子项中的第一个项的y偏移
			int end=this.rect.Bottom;


			foreach(GListViewItem si in this.m_VisableItems)
			{
				if(y>=end)break;
				int h=this.GetItemHeight(si);
				if(item==si)
				{
					if(y>-h)
					{
						return new Rectangle(x,y,w,h);
					}
					else
					{
						break;
					}
				}
				y+=h;
			}
			return Rectangle.Empty;
		}
		internal GListViewItem GetItemAtPoint(Point p)
		{
			Rectangle r=new Rectangle();
			return this.GetItemAtPoint(p,ref r);
		}
		internal GListViewItem GetItemAtPoint(Point p,ref Rectangle rect)
		{
			int x=this.Rect.X;
			int w=this.Rect.Width;
			int start=this.Rect.Y+this.GListView.MinItemHeight;//可以开始画的位置
			int y=start-this.m_GScrollBar.Value;//子项中的第一个项的y偏移
			int end=this.rect.Bottom;


			Rectangle hr=this.Rect;
			if(!hr.Contains(p))
				return null;
			else if(hr.Height>this.GListView.MinItemHeight)
			{
				hr.Height=this.GListView.MinItemHeight;
				if(hr.Contains(p))return this;
			}
			else
			{
				return hr.Contains(p)?this:null;
			}

			foreach(GListViewItem item in this.m_VisableItems)
			{
				if(y>=end)
					break;
				int h=this.GetItemHeight(item);
				if(y>-h)
				{
					Rectangle r=new Rectangle(x,y,w,h);
					r.Intersect(this.Rect);
					if(r.Contains(p))
					{
						rect=r;
						return item;
					}
				}
				y+=h;
			}
			return null;

		}
		internal void OnMouseWheel(MouseEventArgs e)
		{
			if(this.m_GScrollBar.Visible)
			{
		//		int v=this.m_GScrollBar.Value;
			//	v-=(int)(e.Delta/5);
				this.m_GScrollBar.Value-=(int)(e.Delta/5);
			/*	int max=this.m_GScrollBar.Maximum-this.m_GScrollBar.LargeChange;
				int min=0;
				if(v>=max)
				{
					this.m_GScrollBar.Value=max;
				}
				else if(v<=min)
				{
					this.m_GScrollBar.Value=min;
				}
				else
				{
					this.m_GScrollBar.Value=v;
				}*/
			}
	/*		System.Diagnostics.Trace.WriteLine("this.m_GScrollBar.Value "+this.m_GScrollBar.Value.ToString());
			System.Diagnostics.Trace.WriteLine("this.m_GScrollBar.Maximum "+this.m_GScrollBar.Maximum.ToString());
			System.Diagnostics.Trace.WriteLine("this.m_GScrollBar.Minimum "+this.m_GScrollBar.Minimum.ToString());
			System.Diagnostics.Trace.WriteLine("this.m_GScrollBar.LargeChange "+this.m_GScrollBar.LargeChange.ToString());*/
		}
		internal void InvalideteItem(GListViewItem item,State state)
		{
			Rectangle r=this.GetItemRectangle(item);
			this.GListView.OnDrawItem(new GListViewDrawItemEventArgs(this.GListView.CreateGraphics(),r,item,state));
		}
		private void m_GScrollBar_ValueChanged(object sender, EventArgs e)
		{
			this.GListView.Invalidate();
		}

		internal void Update()
		{
			this.ChangeVisableItems();
			this.SetTotalHeight();
			this.SettingScroolBarArguments();
		//	this.Invalidate();
		}
		public override bool Expanded
		{
			get
			{
				return base.Expanded;
			}
			set
			{
				base.Expanded=value;
				if(value)
				{
					if(GListView !=null && this.Parent==null)
					{
						foreach(GListViewItem itm in this.GListView.Items)
						{
							if(itm!=this)itm.expanded=false;
						}
					}
					base.Expanded=true;
				}
			}
		}

	}
}

⌨️ 快捷键说明

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