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

📄 floatingwindow.cs

📁 c#精彩编程百例(源代码)
💻 CS
字号:
//  FloatingWindow.cs
//  Copyright (C) 2001 Mike Krueger
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;

namespace SharpDevelop.Gui.Docking {
	
	public class FloatingWindow : Form
	{
		DockManager     manager;
		DockableControl control;
		bool startup = true;
		
		protected override void OnLocationChanged(EventArgs e)
		{
			if (startup) {
				startup = false;
				return;
			}
			Point rellocation = manager.parent.PointToClient(Location);
			if (manager.parent.ClientRectangle.Contains(rellocation)) {
				if (rellocation.X < 50)
					DockLeft(null, null);
				else 
				if (manager.parent.ClientRectangle.Width - rellocation.X < 50 || manager.parent.ClientRectangle.Width - rellocation.X + Width < 50)
						DockRight(null, null);
				else
				if (rellocation.Y < 50)
					DockTop(null, null);
				else
				if (manager.parent.ClientRectangle.Height - rellocation.Y < 50 || manager.parent.ClientRectangle.Width - rellocation.Y + Height < 50)
					DockBottom(null, null);
			}
			
		}
		
		protected override void OnMouseDown(MouseEventArgs e)
		{
			Console.WriteLine("MouseDown");
			base.OnMouseDown(e);
		}
		
		protected override void OnMove(EventArgs e)
		{
			Point rellocation = manager.parent.PointToClient(Location);
			Console.WriteLine("Move " + rellocation);
		}
		
		public FloatingWindow(DockManager manager, DockableControl control)
		{
			this.manager = manager;
			this.control = control;
			
			control.DockState.Float = true;
			control.FormContainer = this;
			control.formatmenu = new ContextMenu( new MenuItem[] {
				new MenuItem("DockLeft", new EventHandler(DockLeft)),
				new MenuItem("DockRight", new EventHandler(DockRight)),
				new MenuItem("DockBottom", new EventHandler(DockBottom)),
				new MenuItem("DockTop", new EventHandler(DockTop))
			});
			
			ShowInTaskbar = false;
			Text        = control.WindowName;
			TopMost     = true;
			Owner       = manager.parent;
			FormBorderStyle = FormBorderStyle.SizableToolWindow;
			Controls.Add(control);
		}
		
		
		void DockLeft(object sender, EventArgs e)
		{
			control.DockState.DockedIn = DockedIn.LeftContainer;
			manager.left.AddDockableControl(control);
			Close();
		}
		
		void DockRight(object sender, EventArgs e)
		{
			control.DockState.DockedIn = DockedIn.RightContainer;
			manager.right.AddDockableControl(control);
			Close();
		}
		void DockTop(object sender, EventArgs e)
		{
			control.DockState.DockedIn = DockedIn.TopContainer;
			manager.top.AddDockableControl(control);
			Close();
		}
		void DockBottom(object sender, EventArgs e)
		{
			control.DockState.DockedIn = DockedIn.BottomContainer;
			manager.bottom.AddDockableControl(control);
			Close();
		}
		
	}
}

⌨️ 快捷键说明

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