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

📄 splitviewwidget.cs

📁 Fireball.CodeEditor is an source code editor control derived from the best compona SyntaxBox Control
💻 CS
📖 第 1 页 / 共 2 页
字号:
//ORIGINAL LGPL SOURCE CODE FINDED ON COMPONA LGPL SOURCE CODE
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using Fireball.Win32;

namespace Fireball.Windows.Forms
{
	/// <summary>
	/// Summary description for SplitView.
	/// </summary>
	public class SplitViewWidget : Control
	{
		private Panel Vertical;
		private Panel Horizontal;
		private Panel Center;

		private Control _UpperLeft = null;
		private Control _UpperRight = null;
		private Control _LowerLeft = null;
		private Control _LowerRight = null;
		private Point PrevPos = new Point(0);
		private bool FirstTime = false;


		private SizeAction Action = 0;
		private Point StartPos = new Point(0, 0);

		/// <summary>
		/// an event fired when the split view is resized.
		/// </summary>
		public event EventHandler Resizing = null;

		/// <summary>
		/// an event fired when the top views are hidden.
		/// </summary>
		public event EventHandler HideTop = null;

		/// <summary>
		/// an event fired when the left views are hidden.
		/// </summary>
		public event EventHandler HideLeft = null;

		private void OnResizing()
		{
			if (Resizing != null)
				Resizing(this, new EventArgs());
		}

		private void OnHideLeft()
		{
			if (HideLeft != null)
				HideLeft(this, new EventArgs());
		}

		private void OnHideTop()
		{
			if (HideTop != null)
				HideTop(this, new EventArgs());
		}

		private enum SizeAction
		{
			None = 0,
			SizeH = 1,
			SizeV = 2,
			SizeA = 3
		}


		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private Container components = null;

		/// <summary>
		/// Default constructor for the splitview control
		/// </summary>
		public SplitViewWidget()
		{
			// This call is required by the Windows.Forms Form Designer.
			this.SetStyle(ControlStyles.ContainerControl, true);
//			this.SetStyle(ControlStyles.AllPaintingInWmPaint ,false);
//			this.SetStyle(ControlStyles.DoubleBuffer ,false);
//			this.SetStyle(ControlStyles.Selectable,true);
//			this.SetStyle(ControlStyles.ResizeRedraw ,true);
//			this.SetStyle(ControlStyles.Opaque ,true);			
//			this.SetStyle(ControlStyles.UserPaint,true);
			//SetStyle(ControlStyles.Selectable ,true);

			InitializeComponent();


			DoResize();
			ReSize(0, 0);
			//this.Refresh ();
			// TODO: Add any initialization after the InitForm call

		}

//		protected override void OnLoad(EventArgs e)
//		{
//			
//		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose(bool disposing)
		{
#if DEBUG
			try
			{
				Console.WriteLine("disposing splitview");
			}
			catch
			{
			}
#endif
			if (disposing)
			{
				if (components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose(disposing);
		}

		/// <summary>
		/// Gets or Sets the control that should be confined to the upper left view.
		/// </summary>
		public Control UpperLeft
		{
			get { return _UpperLeft; }
			set
			{
				_UpperLeft = value;
				DoResize();
			}
		}

		/// <summary>
		/// Gets or Sets the control that should be confined to the upper right view.
		/// </summary>
		public Control UpperRight
		{
			get { return _UpperRight; }
			set
			{
				_UpperRight = value;
				DoResize();
			}
		}

		/// <summary>
		/// Gets or Sets the control that should be confined to the lower left view.
		/// </summary>
		public Control LowerLeft
		{
			get { return _LowerLeft; }
			set
			{
				_LowerLeft = value;
				DoResize();
			}
		}

		/// <summary>
		/// Gets or Sets the control that should be confined to the lower right view.
		/// </summary>
		public Control LowerRight
		{
			get { return _LowerRight; }
			set
			{
				_LowerRight = value;
				DoResize();
			}
		}

		#region Component Designer generated code

		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Vertical = new System.Windows.Forms.Panel();
			this.Horizontal = new System.Windows.Forms.Panel();
			this.Center = new System.Windows.Forms.Panel();
			this.SuspendLayout();
			// 
			// Vertical
			// 
			this.Vertical.BackColor = System.Drawing.SystemColors.Control;
			this.Vertical.Cursor = System.Windows.Forms.Cursors.VSplit;
			this.Vertical.Name = "Vertical";
			this.Vertical.Size = new System.Drawing.Size(4, 264);
			this.Vertical.TabIndex = 0;
			this.Vertical.Resize += new System.EventHandler(this.Vertical_Resize);
			this.Vertical.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Vertical_MouseUp);
			this.Vertical.DoubleClick += new System.EventHandler(this.Vertical_DoubleClick);
			this.Vertical.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Vertical_MouseMove);
			this.Vertical.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Vertical_MouseDown);
			// 
			// Horizontal
			// 
			this.Horizontal.BackColor = System.Drawing.SystemColors.Control;
			this.Horizontal.Cursor = System.Windows.Forms.Cursors.HSplit;
			this.Horizontal.Name = "Horizontal";
			this.Horizontal.Size = new System.Drawing.Size(320, 4);
			this.Horizontal.TabIndex = 1;
			this.Horizontal.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Horizontal_MouseUp);
			this.Horizontal.DoubleClick += new System.EventHandler(this.Horizontal_DoubleClick);
			this.Horizontal.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Horizontal_MouseMove);
			this.Horizontal.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Horizontal_MouseDown);
			// 
			// Center
			// 
			this.Center.BackColor = System.Drawing.SystemColors.Control;
			this.Center.Cursor = System.Windows.Forms.Cursors.SizeAll;
			this.Center.Location = new System.Drawing.Point(146, 69);
			this.Center.Name = "Center";
			this.Center.Size = new System.Drawing.Size(24, 24);
			this.Center.TabIndex = 2;
			this.Center.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Center_MouseUp);
			this.Center.DoubleClick += new System.EventHandler(this.Center_DoubleClick);
			this.Center.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Center_MouseMove);
			this.Center.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Center_MouseDown);
			// 
			// SplitViewControl
			// 
			this.BackColor = System.Drawing.Color.Magenta;
			this.Controls.AddRange(new System.Windows.Forms.Control[]
				{
					this.Center,
					this.Horizontal,
					this.Vertical
				});
			this.Size = new System.Drawing.Size(200, 200);
			this.VisibleChanged += new System.EventHandler(this.SplitViewControl_VisibleChanged);
			this.Enter += new System.EventHandler(this.SplitViewControl_Enter);
			this.Leave += new System.EventHandler(this.SplitViewControl_Leave);
			this.ResumeLayout(false);

		}

		#endregion

		/// <summary>
		/// 
		/// </summary>
		/// <param name="e"></param>
		protected override void OnResize(EventArgs e)
		{
			DoResize();
		}

		private void DoResize()
		{
			//			int OldWidth=Horizontal.Width ;
			//			int OldHeight=Vertical.Height;
			int NewHeight = this.Height;
			int NewWidth = this.Width;

			if (NewHeight != 0 && NewWidth != 0)
			{
				this.SuspendLayout();
				//				Horizontal.Top = (int)(NewHeight*HorizontalPos);
				//				Vertical.Left =(int)(NewWidth*VerticalPos);
				//
				//				int CenterY=(Horizontal.Top+Horizontal.Height /2)-Center.Height/2;
				//				int CenterX=(Vertical.Left+Vertical.Width /2)-Center.Width /2;
				//
				//				Center.Location =new Point (CenterX,CenterY);


				//ReSize (0,0);
				ReSize2();
				OnResizing();

				if (Horizontal.Top < 15)
				{
					Horizontal.Top = 0 - Horizontal.Height;
					OnHideTop();
				}

				if (Vertical.Left < 15)
				{
					Vertical.Left = 0 - Vertical.Width;
					OnHideLeft();
				}


				Horizontal.Width = this.Width;
				Vertical.Height = this.Height;
				Horizontal.SendToBack();
				Vertical.SendToBack();
				Horizontal.BackColor = SystemColors.Control;
				Vertical.BackColor = SystemColors.Control;


				//this.SendToBack ();
				int RightLeft = Vertical.Left + Vertical.Width;
				int RightLowerTop = Horizontal.Top + Horizontal.Height;
				int RightWidth = this.Width - RightLeft;
				int LowerHeight = this.Height - RightLowerTop;
				int UpperHeight = Horizontal.Top;
				int LeftWidth = Vertical.Left;

				if (LowerRight != null)
				{
					LowerRight.BringToFront();
					LowerRight.SetBounds(RightLeft, RightLowerTop, RightWidth, LowerHeight);
				}
				if (UpperRight != null)
				{
					UpperRight.BringToFront();
					UpperRight.SetBounds(RightLeft, 0, RightWidth, UpperHeight);
				}


				if (LowerLeft != null)
				{
					LowerLeft.BringToFront();
					LowerLeft.SetBounds(0, RightLowerTop, LeftWidth, LowerHeight);
				}
				if (UpperLeft != null)
				{
					UpperLeft.BringToFront();
					UpperLeft.SetBounds(0, 0, LeftWidth, UpperHeight);
				}
				this.ResumeLayout(); //ggf
			}
		}


		/// <summary>
		/// 
		/// </summary>
		/// <param name="e"></param>
		protected override void OnControlAdded(ControlEventArgs e)
		{
			this.DoResize();
		}


		private void Vertical_Resize(object sender, EventArgs e)

⌨️ 快捷键说明

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