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

📄 floatinglform.cs

📁 Magic Library 1.7,有说明文档
💻 CS
📖 第 1 页 / 共 2 页
字号:
// *****************************************************************************
// 
//  (c) Crownwood Consulting Limited 2002 
//  All rights reserved. The software and associated documentation 
//  supplied hereunder are the proprietary information of Crownwood Consulting 
//	Limited, Haxey, North Lincolnshire, England and are supplied subject to 
//	licence terms.
// 
//  Magic Version 1.7 	www.dotnetmagic.com
// *****************************************************************************

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Crownwood.Magic.Win32;
using Crownwood.Magic.Docking;
using Crownwood.Magic.Collections;

namespace Crownwood.Magic.Docking
{
	public class FloatingForm : Form, IHotZoneSource, IMessageFilter
	{
		// Class constants
		private const int HITTEST_CAPTION = 2;

		// Instance variables
        protected Zone _zone;
        protected bool _intercept;
        protected RedockerContent _redocker;
        protected DockingManager _dockingManager;

        // Instance events
        public event ContextHandler Context;
        
        public FloatingForm(DockingManager dockingManager, Zone zone, ContextHandler contextHandler)
        {
            // The caller is responsible for setting our initial screen location
            this.StartPosition = FormStartPosition.Manual;

            // Not in task bar to prevent clutter
            this.ShowInTaskbar = false;
        
            // Make sure the main Form owns us
            this.Owner = dockingManager.Container.FindForm();
            
            // Need to know when the Zone is removed
            this.ControlRemoved += new ControlEventHandler(OnZoneRemoved);
            
            // Add the Zone as the only content of the Form
            Controls.Add(zone);

            // Default state
            _redocker = null;
            _intercept = false;
            _zone = zone;
            _dockingManager = dockingManager;

            // Assign any event handler for context menu
            if (contextHandler != null)
                this.Context += contextHandler;	

            // Default color
            this.BackColor = _dockingManager.BackColor;
            this.ForeColor = _dockingManager.InactiveTextColor;

            // Monitor changes in the Zone content
            _zone.Windows.Inserted += new CollectionChange(OnWindowInserted);
            _zone.Windows.Removing += new CollectionChange(OnWindowRemoving);
            _zone.Windows.Removed += new CollectionChange(OnWindowRemoved);

            if (_zone.Windows.Count == 1)
            {
                // The first Window to be added. Tell it to hide details
                _zone.Windows[0].HideDetails(); 
                
                // Monitor change in window title
                _zone.Windows[0].FullTitleChanged += new EventHandler(OnFullTitleChanged);  

                // Grab any existing title
                this.Text = _zone.Windows[0].FullTitle;
            }
            
            // Need to hook into message pump so that the ESCAPE key can be 
            // intercepted when in redocking mode
            Application.AddMessageFilter(this);
        }

        public DockingManager DockingManager
        {
            get { return _dockingManager; }
        }

        public Zone Zone
        {
            get { return this.Controls[0] as Zone; }
		}

        public void PropogateNameValue(PropogateName name, object value)
        {
            if (this.Zone != null)
                this.Zone.PropogateNameValue(name, value);
        }
        
        public void AddHotZones(Redocker redock, HotZoneCollection collection)
        {
            RedockerContent redocker = redock as RedockerContent;

            // Allow the contained Zone a chance to expose HotZones
            foreach(Control c in this.Controls)
            {
                IHotZoneSource ag = c as IHotZoneSource;

                // Does this control expose an interface for its own HotZones?
                if (ag != null)
                    ag.AddHotZones(redock, collection);
            }
        }
           
        protected void OnWindowInserted(int index, object value)
        {
            if (_zone.Windows.Count == 1)
            {
                // The first Window to be added. Tell it to hide details
                _zone.Windows[0].HideDetails();                
                
                // Monitor change in window title
                _zone.Windows[0].FullTitleChanged += new EventHandler(OnFullTitleChanged);  

                // Grab any existing title
                this.Text = _zone.Windows[0].FullTitle;
            }
            else if (_zone.Windows.Count == 2)
            {
				int pos = 0;
			
				// If the new Window is inserted at beginning then update the second Window
				if (index == 0)
					pos++;

                // The second Window to be added. Tell the first to now show details
                _zone.Windows[pos].ShowDetails();                
                
                // Monitor change in window title
                _zone.Windows[pos].FullTitleChanged -= new EventHandler(OnFullTitleChanged);  

                // Remove any caption title
                this.Text = "";
            }
        }
           
        protected void OnWindowRemoving(int index, object value)
        {
            if (_zone.Windows.Count == 1)
            {   
                // The first Window to be removed. Tell it to show details as we want 
                // to restore the Window state before it might be moved elsewhere
                _zone.Windows[0].ShowDetails();                
                
                // Monitor change in window title
                _zone.Windows[0].FullTitleChanged -= new EventHandler(OnFullTitleChanged);  
                
                // Remove any existing title text
                this.Text = "";
            }
        }

        protected void OnWindowRemoved(int index, object value)
        {
            if (_zone.Windows.Count == 1)
            {   
                // Window removed leaving just one left. Tell it to hide details
                _zone.Windows[0].HideDetails();                

                // Monitor change in window title
                _zone.Windows[0].FullTitleChanged += new EventHandler(OnFullTitleChanged);  
                
                // Grab any existing title text
                this.Text = _zone.Windows[0].FullTitle;
            }
        }
        
        protected void OnFullTitleChanged(object sender, EventArgs e)
        {
            // Unbox sent string
            this.Text = (string)sender;
        }
        
        protected void OnZoneRemoved(object sender, ControlEventArgs e)
        {
			// Is it the Zone being removed for a hidden button used to help
			// remove controls without hitting the 'form refuses to close' bug
			if (e.Control == _zone)
			{
				if (_zone.Windows.Count == 1)
				{   
					// The first Window to be removed. Tell it to show details as we want 
					// to restore the Window state before it might be moved elsewhere
					_zone.Windows[0].ShowDetails();                

					// Remove monitor change in window title
					_zone.Windows[0].FullTitleChanged -= new EventHandler(OnFullTitleChanged);  
				}
        
				// Monitor changes in the Zone content
				_zone.Windows.Inserted -= new CollectionChange(OnWindowInserted);
				_zone.Windows.Removing -= new CollectionChange(OnWindowRemoving);
				_zone.Windows.Removed -= new CollectionChange(OnWindowRemoved);

				// No longer required, commit suicide
				this.Dispose();
			}
        }
        
        protected override CreateParams CreateParams 
        {
            get 
            {
                // Let base class fill in structure first
                CreateParams cp = base.CreateParams;

                // The only way to get a caption bar with only small 
                // close button is by providing this extended style
                cp.ExStyle |= (int)Win32.WindowExStyles.WS_EX_TOOLWINDOW;

                return cp;
            }
        }

        public virtual void OnContext(Point screenPos)
        {
            // Any attached event handlers?
            if (Context != null)
                Context(screenPos);
        }

		public void ExitFloating()
		{
			if (_zone != null)
			{
				ContentCollection cc = ZoneHelper.Contents(_zone);

				// Record restore object for each Content
				foreach(Content c in cc)

⌨️ 快捷键说明

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