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

📄 outlookbar.cs

📁 chaoshi guan li xitong
💻 CS
📖 第 1 页 / 共 5 页
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.Reflection;
using System.IO;
using System.Drawing.Design;

using UtilityLibrary.Collections;
using UtilityLibrary.Win32;
using UtilityLibrary.General;
using UtilityLibrary.Menus;

namespace UtilityLibrary.WinControls
{
		
	#region Delegates
	public delegate void OutlookBarPropertyChangedHandler(OutlookBarBand band, OutlookBarProperty property);
	public delegate void OutlookBarItemClickedHandler(OutlookBarBand band, OutlookBarItem item);
	public delegate void OutlookBarItemDroppedHandler(OutlookBarBand band, OutlookBarItem item);
	public delegate void OutlookBarIconViewChangedHandler(OutlookBarBand band);
	#endregion

	#region Enumerations
	public enum OutlookBarProperty
	{
		CurrentBandChanged,
		ShortcutNameChanged,
		GroupNameChanged
	}

	enum ItemSizeType
	{
		Icon,
		Label,
		All
	}

	public enum IconView
	{
		Small,
		Large
	}

	public enum HitTestType
	{
		UpScroll,
		DownScroll,
		Header,
		Item,
		DropLine,
		DropLineLastItem,
		Nothing
	}

	public enum ContextMenuType
	{
		Item,
		Header,
		Bar
	}

	public enum BorderType
	{
		None,
		FixedSingle,
		Fixed3D,
		Custom
	}
	#endregion

	#region OutlookBarBand class
	[ToolboxItem(false)]
	public class OutlookBarBand : Control
	{
		#region Class variables
		Control childControl = null;
        ImageList smallImageList = null;
		ImageList largeImageList = null;
		OutlookBarItemCollection items = null;
		Color background = ColorUtil.VSNetControlColor;
		Color textColor = SystemColors.ControlText;
		IconView iconView = IconView.Large;
		#endregion

		#region Events
		public event OutlookBarIconViewChangedHandler IconViewChanged;
		#endregion
						        		
		#region Constructors
		public OutlookBarBand(string text, Control childControl)
		{
			this.Text = text;
			this.childControl = childControl;
		}

		public OutlookBarBand(string text)
		{
			this.Text = text;
			// When using the constructor that just use the name,
			// it means that this band will have child items
			items = new OutlookBarItemCollection();
		}

		public OutlookBarBand()
		{
			// Constructor for designer support
			items = new OutlookBarItemCollection();
			if( this.Site!= null)
				Name = Site.Name;
			else
				Name = null;
		}
		#endregion

		#region Overrides
		protected override void Dispose( bool disposing )
		{
			if( items!= null)
				items.Clear();
			base.Dispose( disposing);
		}
		#endregion

		private void InitializeComponent()
		{

		}
        
		#region Properties
		public Control ChildControl
		{
			get { return childControl; }
		}

		public ImageList SmallImageList
		{
			set { smallImageList = value; }
			get { return smallImageList; }
		}

		public ImageList LargeImageList
		{
			set { largeImageList = value; }
			get { return largeImageList; }
		}

		public Color Background
		{
			set { background = value; }
			get { return background; }
		}

		public Color TextColor
		{
			set { textColor = value; }
			get { return textColor; }
		}

		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public OutlookBarItemCollection Items
		{
			get { return items; }
		}

		public IconView IconView 
		{
			set { iconView = value; }
			get { return iconView; }
		}
		#endregion

		#region Methods
		#endregion

		#region Implementation
		void FireIconViewChanged()
		{
			if ( IconViewChanged != null )
			{
				IconViewChanged(this);
			}
		}
		#endregion
	
	}
	#endregion

	#region OutlookBar Item class
	[ToolboxItem(false)]
	public class OutlookBarItem : Component
	{
		#region Class variables
		string text;
        int imageIndex = -1;
		object tag;
		#endregion

		#region Events
		#endregion
		
		#region Constructors
		public OutlookBarItem(string text, int ImageIndex)
		{
			this.text = text;
			this.imageIndex = ImageIndex;
		}

		public OutlookBarItem(string text, int imageIndex, object tag)
		{
			this.text = text;
			this.imageIndex = imageIndex;
			tag = tag;
		}

		public OutlookBarItem()
		{
			// To support designer
			imageIndex = -1;
		}

		#endregion

		#region Overrides
		#endregion

		#region Methods 
		#endregion
		
		#region Properties
		public int ImageIndex
		{
			set { imageIndex = value; }
			get { return imageIndex; }
		}

		public string Text
		{
			set { text = value; }
			get { return text; }
		}

		public object Tag
		{
			set { tag = value; }
			get { return tag; }
		}

		#endregion

		#region Implementation
		#endregion
	}
	#endregion

    #region OutlookBar class
	[ToolboxBitmap(typeof(UtilityLibrary.WinControls.OutlookBar), 
    "UtilityLibrary.WinControls.OutlookBar.bmp")]
	public class OutlookBar : System.Windows.Forms.Control
	{
		
		#region Class variables
		const int BAND_HEADER_HEIGHT = 22;
		int currentBandIndex = -1;
		BorderType borderType = BorderType.None;
		int firstItem = 0;
		int lastHighlightedHeader = -1;
		int lastHighlightedItem = -1;
		Rectangle upArrowRect;
		Rectangle downArrowRect;
		DrawState upArrowDrawState = DrawState.Normal;
		DrawState downArrowDrawState = DrawState.Normal;
		bool upArrowVisible = false;
		bool downArrowVisible = false;
		bool upArrowPressed = false;
		bool downArrowPressed = false;
		bool upTimerTicking = false;
		bool downTimerTicking = false;
		bool doScrollingLoop = false;
		bool buttonPushed = false;
		Bitmap backgroundBitmap = null;
		bool needBackgroundBitmapResize = true;
		bool flatArrowButtons = false;
			
		// Custom Border colors
		Color leftTopColor = Color.Empty;
		Color rightBottomColor = Color.Empty;
		
		// Context Menus
		ContextMenu contextMenu = null;
		Point lastClickedPoint = Point.Empty;
		
		int selectedHeader = -1;
		System.Windows.Forms.Timer highlightTimer = new System.Windows.Forms.Timer();
		bool previousPressed = false;
		int animationSpeed = 20;
		Cursor dragCursor = null;
		int lastDrawnLineIndex = -1;
        bool paintedDropLineLastItem = false;
		int droppedPosition = -1;
		bool forceHightlight = false;
		int forceHightlightIndex = -1;
		
		// For in place editing of the 
		TextBoxEx textBox = new TextBoxEx();
		bool editingAnItem = false;
        						
		const int X_SMALLICON_LABEL_OFFSET = 2;
		const int Y_LARGEICON_LABEL_OFFSET = 3;
		const int Y_SMALLICON_SPACING = 10;
		const int Y_LARGEICON_SPACING = 8;
		const int LEFT_MARGIN = 5;
		const int LARGE_TOP_MARGIN = 10;
		const int SMALL_TOP_MARGIN = 6;
		const int ARROW_BUTTON_MARGIN = 5;

		// Flat Arrow Buttons helpers
		DrawState upFlatArrowState = DrawState.Normal;
		DrawState downFlatArrowState = DrawState.Normal;
		
		// Bands
		OutlookBarBandCollection bands = null;
		#endregion

		#region Events
		public event OutlookBarPropertyChangedHandler PropertyChanged;
		public event OutlookBarItemClickedHandler ItemClicked;
		public event OutlookBarItemDroppedHandler ItemDropped;
		#endregion
				
		#region Constructors
		public OutlookBar()
		{
            // Construct band collection
			bands = new OutlookBarBandCollection(this);

			Dock = DockStyle.Left;
			// We are going to do all of the painting so better setup the control
			// to use double buffering
			SetStyle(ControlStyles.AllPaintingInWmPaint|ControlStyles.ResizeRedraw
				|ControlStyles.Opaque|ControlStyles.UserPaint|ControlStyles.DoubleBuffer, true);
			Font = SystemInformation.MenuFont;
			
			CreateContextMenu();

			// Setup timer
			highlightTimer.Tick += new EventHandler(OnHighlightHeader);
			highlightTimer.Interval = 100;

			// Load drag cursor
			Assembly myAssembly = Assembly.GetAssembly(Type.GetType("UtilityLibrary.WinControls.OutlookBar"));
            Stream cursorStream = myAssembly.GetManifestResourceStream("UtilityLibrary.Resources.DragCursor.cur");
			dragCursor = new Cursor(cursorStream);
               
			// don't display it until we need to
			textBox.Visible = false;
			// Hook up notification for the Enter and LostFocus events
			textBox.KeyUp += new KeyEventHandler(TextBoxKeyDown);
			textBox.LostFocus += new EventHandler(TextBoxLostFocus);

		}
		#endregion

		#region Overrides
		protected override Size DefaultSize
		{
			get { return new Size(100, 10); }
		}

		protected override void OnPaint(PaintEventArgs pe)
		{
			base.OnPaint(pe);
			Graphics g = pe.Graphics;
			
			// Manipulate child window in case there is one
			if ( currentBandIndex == -1 && bands.Count > 0)
				SetCurrentBand(0);
			
			// Background if it needs to be painted
			DrawBackground(g);
			// If we have a border
			DrawBorder(g);
			// The little headers
			DrawHeaders(g);
			
			// If there is a child window
			// it will paint itself, otherwise we do the painting
			if ( !HasChild() )
			{
				// The items themselves
				DrawItems(g, Rectangle.Empty, null);

				// The buttons for scrolling items
				// Drawing second so that they don't get written over by the items
				DrawArrowButtons(g);
			}

			// Highlight last item clicked
			if ( forceHightlight )
			{
                ForceHighlightItem(g, forceHightlightIndex);
				forceHightlight = false;
			}

		}

		protected override void OnMouseDown(MouseEventArgs e)
		{
			base.OnMouseDown(e);
			// If the textbox is being displayed cancel editing
			if ( textBox.Visible )
			{
				ProcessTextBoxEditing();
				return;
			}

			int index;
			HitTestType ht = HitTest(new Point(e.X, e.Y), out index, false);
			if ( e.Button == MouseButtons.Left)
			{
				// Handle arrow button hit
				if( ht == HitTestType.UpScroll || ht == HitTestType.DownScroll)
				{
					if ( ht == HitTestType.UpScroll )
					{
						ProcessArrowScrolling(upArrowRect,   
							ref upArrowVisible, ref upArrowPressed, ref upTimerTicking);
						return;
					}
					else
					{
						ProcessArrowScrolling(downArrowRect, 
							ref downArrowVisible, ref downArrowPressed, ref downTimerTicking);
						return;
					}
				}
                
				// Handle header hit
				if ( ht == HitTestType.Header )
				{
					ProcessHeaderHit(index);
					return;
				}

				// Handle item hit
				if ( ht == HitTestType.Item )
				{
					ProcessItemHit(index, new Point(e.X, e.Y));
					return;
				}
			}
		}

		protected override void OnMouseMove(MouseEventArgs e)
		{
			base.OnMouseMove(e);
           		
			Point MousePos = new Point(e.X, e.Y);

			// Change cursor if over a header
			int index;
			HitTestType ht = HitTest(MousePos, out index, false);

			if ( ht != HitTestType.Header && lastHighlightedHeader >=0 )HighlightHeader(-1);			
			if ( ht != HitTestType.Item  && lastHighlightedItem  >= 0 ) HighlightItem(-1, false);
			
			if ( upArrowDrawState == DrawState.Hot && ht != HitTestType.UpScroll
				|| flatArrowButtons )

⌨️ 快捷键说明

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