autohidestripvs2003.cs

来自「SharpDevelop2.0.0 c#开发免费工具」· CS 代码 · 共 489 行 · 第 1/2 页

CS
489
字号
// *****************************************************************************
// 
//  Copyright 2004, Weifen Luo
//  All rights reserved. The software and associated documentation 
//  supplied hereunder are the proprietary information of Weifen Luo
//  and are supplied subject to licence terms.
// 
//  WinFormsUI Library Version 1.0
// *****************************************************************************
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace WeifenLuo.WinFormsUI
{
	/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/ClassDef/*'/>
	public class AutoHideStripVS2003 : AutoHideStripBase
	{
		private const int _ImageHeight = 16;
		private const int _ImageWidth = 16;
		private const int _ImageGapTop = 2;
		private const int _ImageGapLeft = 4;
		private const int _ImageGapRight = 4;
		private const int _ImageGapBottom = 2;
		private const int _TextGapLeft = 4;
		private const int _TextGapRight = 10;
		private const int _TabGapTop = 3;
		private const int _TabGapLeft = 2;
		private const int _TabGapBetween = 10;

		private static Matrix _matrixIdentity;
		private static DockState[] _dockStates;

		#region Customizable Properties
		private static StringFormat _stringFormatTabHorizontal = null;
		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="StringFormatTabHorizontal"]/*'/>
		protected virtual StringFormat StringFormatTabHorizontal
		{
			get
			{	
				if (_stringFormatTabHorizontal == null)
				{
					_stringFormatTabHorizontal = new StringFormat();
					_stringFormatTabHorizontal.Alignment = StringAlignment.Near;
					_stringFormatTabHorizontal.LineAlignment = StringAlignment.Center;
					_stringFormatTabHorizontal.FormatFlags = StringFormatFlags.NoWrap;
				}
				return _stringFormatTabHorizontal;
			}
		}

		private static StringFormat _stringFormatTabVertical;
		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="StringFormatTabVertical"]/*'/>
		protected virtual StringFormat StringFormatTabVertical
		{
			get
			{	
				if (_stringFormatTabVertical == null)
				{
					_stringFormatTabVertical = new StringFormat();
					_stringFormatTabVertical.Alignment = StringAlignment.Near;
					_stringFormatTabVertical.LineAlignment = StringAlignment.Center;
					_stringFormatTabVertical.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.DirectionVertical;
				}
				return _stringFormatTabVertical;
			}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="ImageHeight"]/*'/>
		protected virtual int ImageHeight
		{
			get	{	return _ImageHeight;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="ImageWidth"]/*'/>
		protected virtual int ImageWidth
		{
			get	{	return _ImageWidth;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="ImageGapTop"]/*'/>
		protected virtual int ImageGapTop
		{
			get	{	return _ImageGapTop;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="ImageGapLeft"]/*'/>
		protected virtual int ImageGapLeft
		{
			get	{	return _ImageGapLeft;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="ImageGapRight"]/*'/>
		protected virtual int ImageGapRight
		{
			get	{	return _ImageGapRight;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="ImageGapBottom"]/*'/>
		protected virtual int ImageGapBottom
		{
			get	{	return _ImageGapBottom;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="TextGapLeft"]/*'/>
		protected virtual int TextGapLeft
		{
			get	{	return _TextGapLeft;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="TextGapRight"]/*'/>
		protected virtual int TextGapRight
		{
			get	{	return _TextGapRight;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="TabGapTop"]/*'/>
		protected virtual int TabGapTop
		{
			get	{	return _TabGapTop;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="TabGapLeft"]/*'/>
		protected virtual int TabGapLeft
		{
			get	{	return _TabGapLeft;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="TabGapBetween"]/*'/>
		protected virtual int TabGapBetween
		{
			get	{	return _TabGapBetween;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="BrushTabBackground"]/*'/>
		protected virtual Brush BrushTabBackground
		{
			get	{	return SystemBrushes.Control;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="PenTabBorder"]/*'/>
		protected virtual Pen PenTabBorder
		{
			get	{	return SystemPens.GrayText;	}
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Property[@name="BrushTabText"]/*'/>
		protected virtual Brush BrushTabText
		{
			get	{	return SystemBrushes.FromSystemColor(SystemColors.ControlDarkDark);	}
		}
		#endregion

		private Matrix MatrixIdentity
		{
			get	{	return _matrixIdentity;	}
		}

		private DockState[] DockStates
		{
			get	{	return _dockStates;	}
		}

		static AutoHideStripVS2003()
		{
			_matrixIdentity = new Matrix();

			_dockStates = new DockState[4];
			_dockStates[0] = DockState.DockLeftAutoHide;
			_dockStates[1] = DockState.DockRightAutoHide;
			_dockStates[2] = DockState.DockTopAutoHide;
			_dockStates[3] = DockState.DockBottomAutoHide;
		}

		/// <include file='CodeDoc/AutoHideStripVS2003.xml' path='//CodeDoc/Class[@name="AutoHideStripVS2003"]/Construct[@name="(DockPanel)"]/*'/>
		protected internal AutoHideStripVS2003(DockPanel panel) : base(panel)
		{
			SetStyle(ControlStyles.ResizeRedraw, true);
			SetStyle(ControlStyles.UserPaint, true);
			SetStyle(ControlStyles.AllPaintingInWmPaint, true);
			SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
			BackColor = Color.WhiteSmoke;
		}

		/// <exclude/>
		protected override void OnPaint(PaintEventArgs e)
		{
			Graphics g = e.Graphics;
			DrawTabStrip(g);
		}

		/// <exclude/>
		protected override void OnLayout(LayoutEventArgs levent)
		{
			CalculateTabs();
			base.OnLayout (levent);
		}

		private void DrawTabStrip(Graphics g)
		{
			DrawTabStrip(g, DockState.DockTopAutoHide);
			DrawTabStrip(g, DockState.DockBottomAutoHide);
			DrawTabStrip(g, DockState.DockLeftAutoHide);
			DrawTabStrip(g, DockState.DockRightAutoHide);
		}

		private void DrawTabStrip(Graphics g, DockState dockState)
		{
			Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState);

			if (rectTabStrip.IsEmpty)
				return;

			Matrix matrixIdentity = g.Transform;
			if (dockState == DockState.DockLeftAutoHide || dockState == DockState.DockRightAutoHide)
			{
				Matrix matrixRotated = new Matrix();
				matrixRotated.RotateAt(90, new PointF((float)rectTabStrip.X + (float)rectTabStrip.Height / 2,
					(float)rectTabStrip.Y + (float)rectTabStrip.Height / 2));
				g.Transform = matrixRotated;
			}

			foreach (AutoHidePane pane in GetPanes(dockState))
			{
				foreach (AutoHideTabVS2003 tab in pane.Tabs)
					DrawTab(g, tab);
			}
			g.Transform = matrixIdentity;
		}

		private void CalculateTabs()
		{
			CalculateTabs(DockState.DockTopAutoHide);
			CalculateTabs(DockState.DockBottomAutoHide);
			CalculateTabs(DockState.DockLeftAutoHide);
			CalculateTabs(DockState.DockRightAutoHide);
		}

		private void CalculateTabs(DockState dockState)
		{
			Rectangle rectTabStrip = GetLogicalTabStripRectangle(dockState);

			int imageHeight = rectTabStrip.Height - ImageGapTop - ImageGapBottom;
			int imageWidth = ImageWidth;

⌨️ 快捷键说明

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