📄 sampledocking.cs
字号:
// *****************************************************************************
//
// (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.Xml;
using System.Data;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Crownwood.Magic.Common;
using Crownwood.Magic.Controls;
using Crownwood.Magic.Docking;
using Crownwood.Magic.Menus;
public class SampleDocking : Form
{
protected byte[] _slot1;
protected byte[] _slot2;
protected int _count = 0;
protected int _ignoreClose = 0;
protected int _colorIndex = 0;
protected bool _allowContextMenu = true;
protected bool _customContextMenu = false;
protected bool _tabsBottom = true;
protected bool _captionBars = true;
protected bool _closeButtons = true;
protected VisualStyle _style;
protected MenuCommand _placeHolder;
protected DockingManager _manager;
protected ImageList _internalImages;
protected StatusBar _statusBar;
protected Crownwood.Magic.Menus.MenuControl _topMenu;
protected Crownwood.Magic.Controls.TabControl _filler;
protected Crownwood.Magic.Controls.TabControl.VisualAppearance _tabAppearance = Crownwood.Magic.Controls.TabControl.VisualAppearance.MultiForm;
[STAThread]
public static void Main()
{
Application.Run(new SampleDocking());
}
public SampleDocking()
{
// Discover which docking manager to use
if (DialogResult.Yes == MessageBox.Show("Press 'Yes' to select IDE appearance\n\n" +
"Press 'No' to select Plain appearance\n",
"Select Visual Style", MessageBoxButtons.YesNo))
_style = VisualStyle.IDE;
else
_style = VisualStyle.Plain;
InitializeComponent();
// Create a strip of images by loading an embedded bitmap resource
_internalImages = ResourceHelper.LoadBitmapStrip(this.GetType(),
"SampleDocking.SampleImages.bmp",
new Size(16,16),
new Point(0,0));
BorderStyle bs = (_style == VisualStyle.Plain) ? BorderStyle.None : BorderStyle.FixedSingle;
RichTextBox rtb1 = new RichTextBox();
RichTextBox rtb2 = new RichTextBox();
RichTextBox rtb3 = new RichTextBox();
rtb1.BorderStyle = bs;
rtb2.BorderStyle = bs;
rtb3.BorderStyle = bs;
_filler = new Crownwood.Magic.Controls.TabControl();
_filler.TabPages.Add(new Crownwood.Magic.Controls.TabPage("First", rtb1));
_filler.TabPages.Add(new Crownwood.Magic.Controls.TabPage("Second", rtb2));
_filler.TabPages.Add(new Crownwood.Magic.Controls.TabPage("Third", rtb3));
_filler.Appearance = Crownwood.Magic.Controls.TabControl.VisualAppearance.MultiDocument;
_filler.Dock = DockStyle.Fill;
_filler.Style = _style;
_filler.IDEPixelBorder = true;
Controls.Add(_filler);
// Reduce the amount of flicker that occurs when windows are redocked within
// the container. As this prevents unsightly backcolors being drawn in the
// WM_ERASEBACKGROUND that seems to occur.
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
// Create the object that manages the docking state
_manager = new DockingManager(this, _style);
// Notifications
_manager.ContextMenu += new DockingManager.ContextMenuHandler(OnContextMenu);
_manager.ContentHiding += new DockingManager.ContentHidingHandler(OnContentHiding);
_manager.TabControlCreated += new DockingManager.TabControlCreatedHandler(OnTabControlCreated);
// Ensure that the RichTextBox is always the innermost control
_manager.InnerControl = _filler;
// Create and setup the StatusBar object
_statusBar = new StatusBar();
_statusBar.Dock = DockStyle.Bottom;
_statusBar.ShowPanels = true;
// Create and setup a single panel for the StatusBar
StatusBarPanel statusBarPanel = new StatusBarPanel();
statusBarPanel.AutoSize = StatusBarPanelAutoSize.Spring;
_statusBar.Panels.Add(statusBarPanel);
Controls.Add(_statusBar);
_topMenu = CreateMenus();
// Ensure that docking occurs after the menu control and status bar controls
_manager.OuterControl = _statusBar;
// Setup custom config handling
_manager.SaveCustomConfig += new DockingManager.SaveCustomConfigHandler(OnSaveConfig);
_manager.LoadCustomConfig += new DockingManager.LoadCustomConfigHandler(OnLoadConfig);
}
protected Crownwood.Magic.Menus.MenuControl CreateMenus()
{
Crownwood.Magic.Menus.MenuControl topMenu = new Crownwood.Magic.Menus.MenuControl();
topMenu.Style = _style;
topMenu.MultiLine = false;
MenuCommand topManager = new MenuCommand("Manager");
MenuCommand topConfig = new MenuCommand("Config");
MenuCommand topSettings = new MenuCommand("Settings");
MenuCommand topColors = new MenuCommand("Colors");
MenuCommand topTabControls = new MenuCommand("TabControls");
topMenu.MenuCommands.AddRange(new MenuCommand[]{topManager, topConfig, topSettings,topColors,topTabControls});
// Manager
MenuCommand managerC1 = new MenuCommand("Create Form", new EventHandler(OnCreateC1));
MenuCommand managerC2 = new MenuCommand("Create Panel", new EventHandler(OnCreateC2));
MenuCommand managerC3 = new MenuCommand("Create RichTextBox", new EventHandler(OnCreateC3));
MenuCommand managerSep1 = new MenuCommand("-");
MenuCommand managerC31 = new MenuCommand("Create 3 in Row", new EventHandler(OnCreateC31));
MenuCommand managerC32 = new MenuCommand("Create 3 in Column", new EventHandler(OnCreateC32));
MenuCommand managerC33 = new MenuCommand("Create 3 in Window", new EventHandler(OnCreateC33));
MenuCommand managerSep2 = new MenuCommand("-");
MenuCommand managerFF = new MenuCommand("Create 3 in Floating Form", new EventHandler(OnCreateFF));
MenuCommand managerSep3 = new MenuCommand("-");
MenuCommand managerClear = new MenuCommand("Delete Contents", new EventHandler(OnDeleteAll));
MenuCommand managerSep4 = new MenuCommand("-");
MenuCommand managerShowAll = new MenuCommand("Show All", new EventHandler(OnShowAll));
MenuCommand managerHideAll = new MenuCommand("Hide All", new EventHandler(OnHideAll));
MenuCommand managerSep5 = new MenuCommand("-");
MenuCommand managerInsideFill = new MenuCommand("Inside Fill", new EventHandler(OnInsideFill));
MenuCommand managerSep6 = new MenuCommand("-");
MenuCommand managerExit = new MenuCommand("Exit", new EventHandler(OnExit));
managerInsideFill.Update += new EventHandler(OnUpdateInsideFill);
topManager.MenuCommands.AddRange(new MenuCommand[]{managerC1,managerC2,managerC3,managerSep1,
managerC31,managerC32,managerC33,managerSep2,
managerFF,managerSep3,
managerClear,managerSep4,managerShowAll,
managerHideAll,managerSep5,managerInsideFill,
managerSep5,managerExit});
// Config
MenuCommand configSF1 = new MenuCommand("Save as Config1.xml", new EventHandler(OnSaveFile1));
MenuCommand configSF2 = new MenuCommand("Save as Config2.xml", new EventHandler(OnSaveFile2));
MenuCommand configSep1 = new MenuCommand("-");
MenuCommand configLF1 = new MenuCommand("Load from Config1.xml", new EventHandler(OnLoadFile1));
MenuCommand configLF2 = new MenuCommand("Load from Config2.xml", new EventHandler(OnLoadFile2));
MenuCommand configSep2 = new MenuCommand("-");
MenuCommand configSA1 = new MenuCommand("Save to byte array1", new EventHandler(OnSaveArray1));
MenuCommand configSA2 = new MenuCommand("Save to byte array2", new EventHandler(OnSaveArray2));
MenuCommand configSep3 = new MenuCommand("-");
MenuCommand configLA1 = new MenuCommand("Load from byte array1", new EventHandler(OnLoadArray1));
MenuCommand configLA2 = new MenuCommand("Load from byte array2", new EventHandler(OnLoadArray2));
topConfig.MenuCommands.AddRange(new MenuCommand[]{configSF1,configSF2,configSep1,
configLF1,configLF2,configSep2,
configSA1,configSA2,configSep3,
configLA1,configLA2});
// Settings
MenuCommand settingsShow = new MenuCommand("Allow Context Menu", new EventHandler(OnContextMenuAllow));
MenuCommand settingsCustom = new MenuCommand("Customize Context Menu", new EventHandler(OnContextMenuCustomize));
MenuCommand settingsSep1 = new MenuCommand("-");
MenuCommand settingsRSBD = new MenuCommand("Default ResizeBarVector", new EventHandler(OnResizeBarDefault));
MenuCommand settingsRSB1 = new MenuCommand("1 Pixel ResizeBarVector", new EventHandler(OnResizeBar1));
MenuCommand settingsRSB5 = new MenuCommand("5 Pixel ResizeBarVector", new EventHandler(OnResizeBar5));
MenuCommand settingsRSB7 = new MenuCommand("7 Pixel ResizeBarVector", new EventHandler(OnResizeBar7));
MenuCommand settingsSep2 = new MenuCommand("-");
MenuCommand settingsCaptionBars = new MenuCommand("Show all caption bars", new EventHandler(OnCaptionBars));
MenuCommand settingsCloseButtons = new MenuCommand("Show all close buttons", new EventHandler(OnCloseButtons));
MenuCommand settingsSep3 = new MenuCommand("-");
MenuCommand settingsAllow = new MenuCommand("Allow all close buttons", new EventHandler(OnAllowAllCloseButton));
MenuCommand settingsIgnoreAll = new MenuCommand("Ignore all close buttons", new EventHandler(OnIgnoreAllCloseButton));
MenuCommand settingsIgnorePanel = new MenuCommand("Ignore all Panel close buttons", new EventHandler(OnIgnoreAllPanelButton));
MenuCommand settingsIgnoreForm = new MenuCommand("Ignore all Form close buttons", new EventHandler(OnIgnoreAllFormButton));
MenuCommand settingsIgnoreTextBox = new MenuCommand("Ignore all RichTextBox close buttons", new EventHandler(OnIgnoreAllTextboxButton));
MenuCommand settingsSep4 = new MenuCommand("-");
MenuCommand settingsAllowMinMax = new MenuCommand("Enable Min/Max in Columns/Rows", new EventHandler(OnAllowMinMax));
MenuCommand settingsSep5 = new MenuCommand("-");
MenuCommand settingsPlainTabBorder = new MenuCommand("Show Plain Tab Border", new EventHandler(OnPlainTabBorder));
settingsShow.Update += new EventHandler(OnUpdateAllow);
settingsCustom.Update += new EventHandler(OnUpdateCustomize);
settingsRSBD.Update += new EventHandler(OnUpdateRSBD);
settingsRSB1.Update += new EventHandler(OnUpdateRSB1);
settingsRSB5.Update += new EventHandler(OnUpdateRSB5);
settingsRSB7.Update += new EventHandler(OnUpdateRSB7);
settingsCaptionBars.Update += new EventHandler(OnUpdateCaptionBars);
settingsCloseButtons.Update += new EventHandler(OnUpdateCloseButtons);
settingsAllow.Update += new EventHandler(OnUpdateAllowAll);
settingsIgnoreAll.Update += new EventHandler(OnUpdateIgnoreAll);
settingsIgnorePanel.Update += new EventHandler(OnUpdateIgnorePanel);
settingsIgnoreForm.Update += new EventHandler(OnUpdateIgnoreForm);
settingsIgnoreTextBox.Update += new EventHandler(OnUpdateIgnoreTextBox);
settingsAllowMinMax.Update += new EventHandler(OnUpdateAllowMinMax);
settingsPlainTabBorder.Update += new EventHandler(OnUpdatePlainTabBorder);
topSettings.MenuCommands.AddRange(new MenuCommand[]{settingsShow,settingsCustom,settingsSep1,settingsRSBD,
settingsRSB1,settingsRSB5,settingsRSB7,settingsSep2,
settingsCaptionBars,settingsCloseButtons,settingsSep3,
settingsAllow,settingsIgnoreAll,settingsIgnorePanel,
settingsIgnoreForm,settingsIgnoreTextBox,settingsSep4,
settingsAllowMinMax,settingsSep5,settingsPlainTabBorder});
// Colors
MenuCommand colorDefault = new MenuCommand("System Default", new EventHandler(OnColorDefault));
MenuCommand colorSlateBlue = new MenuCommand("Custom - Slate Blue", new EventHandler(OnColorSlateBlue));
MenuCommand colorFirebrick = new MenuCommand("Custom - Firebrick", new EventHandler(OnColorFirebrick));
MenuCommand colorGreen = new MenuCommand("Custom - Green", new EventHandler(OnColorGreen));
colorDefault.Update += new EventHandler(OnUpdateDefault);
colorSlateBlue.Update += new EventHandler(OnUpdateSlateBlue);
colorFirebrick.Update += new EventHandler(OnUpdateFirebrick);
colorGreen.Update += new EventHandler(OnUpdateGreen);
topColors.MenuCommands.AddRange(new MenuCommand[]{colorDefault,colorSlateBlue,colorFirebrick,colorGreen});
// TabControls
MenuCommand tabsBox = new MenuCommand("MultiBox", new EventHandler(OnTabsMultiBox));
MenuCommand tabsForm = new MenuCommand("MultiForm", new EventHandler(OnTabsMultiForm));
MenuCommand tabsDocument = new MenuCommand("MultiDocument", new EventHandler(OnTabsMultiDocument));
MenuCommand tabsSep1 = new MenuCommand("-");
MenuCommand tabsTop = new MenuCommand("Tabs at top", new EventHandler(OnTabsTop));
MenuCommand tabsBottom = new MenuCommand("Tabs at bottom", new EventHandler(OnTabsBottom));
tabsBox.Update += new EventHandler(OnUpdateTabsBox);
tabsForm.Update += new EventHandler(OnUpdateTabsForm);
tabsDocument.Update += new EventHandler(OnUpdateTabsDocument);
tabsTop.Update += new EventHandler(OnUpdateTabsTop);
tabsBottom.Update += new EventHandler(OnUpdateTabsBottom);
topTabControls.MenuCommands.AddRange(new MenuCommand[]{tabsBox,tabsForm,tabsDocument,
tabsSep1,tabsTop,tabsBottom});
topMenu.Dock = DockStyle.Top;
Controls.Add(topMenu);
return topMenu;
}
protected void OnContextMenu(PopupMenu pm, CancelEventArgs cea)
{
// Show the PopupMenu be cancelled and not shown?
if (!_allowContextMenu)
cea.Cancel = true;
else
{
if (_customContextMenu)
{
// Remove the Show All and Hide All commands
pm.MenuCommands.Remove(pm.MenuCommands["Show All"]);
pm.MenuCommands.Remove(pm.MenuCommands["Hide All"]);
// Add a custom item at the start
pm.MenuCommands.Insert(0, (new MenuCommand("Custom 1")));
pm.MenuCommands.Insert(1, (new MenuCommand("-")));
// Add a couple of custom commands at the end
pm.MenuCommands.Add(new MenuCommand("Custom 2"));
pm.MenuCommands.Add(new MenuCommand("Custom 3"));
}
}
}
protected void OnContentHiding(Content c, CancelEventArgs cea)
{
switch(_ignoreClose)
{
case 0:
// Allow all, do nothing
break;
case 1:
// Ignore all, cancel
cea.Cancel = true;
break;
case 2:
// Ignore Panels
cea.Cancel = c.Control is Panel;
break;
case 3:
// Ignore Forms
cea.Cancel = c.Control is Form;
break;
case 4:
// Ignore RichTextBox
cea.Cancel = c.Control is RichTextBox;
break;
}
}
protected void OnTabControlCreated(Crownwood.Magic.Controls.TabControl tabControl)
{
tabControl.PositionTop = !_tabsBottom;
tabControl.Appearance = _tabAppearance;
}
protected void OnContextMenuAllow(object sender, EventArgs e)
{
// Toggle the display of the docking windows context menu
_allowContextMenu = (_allowContextMenu == false);
}
protected void OnUpdateAllow(object sender, EventArgs e)
{
MenuCommand allowCommand = sender as MenuCommand;
allowCommand.Checked = _allowContextMenu;
}
protected void OnContextMenuCustomize(object sender, EventArgs e)
{
// Toggle the customization of the displayed context menu
_customContextMenu = (_customContextMenu == false);
}
protected void OnUpdateCustomize(object sender, EventArgs e)
{
MenuCommand customizeCommand = sender as MenuCommand;
customizeCommand.Checked = _customContextMenu;
}
protected void OnInsideFill(object sender, EventArgs e)
{
if (_manager.InsideFill)
{
Controls.Add(_filler);
Controls.SetChildIndex(_filler, 0);
_manager.InnerControl = _filler;
_manager.InsideFill = false;
}
else
{
Controls.Remove(_filler);
_manager.InnerControl = null;
_manager.InsideFill = true;
}
}
protected void OnUpdateInsideFill(object sender, EventArgs e)
{
MenuCommand fillCommand = sender as MenuCommand;
fillCommand.Checked = _manager.InsideFill;
}
protected void OnCreateC1(object sender, EventArgs e)
{
// Create Content which contains a RichTextBox
Content c = _manager.Contents.Add(new DummyForm(), "Form " + _count++, _internalImages, _count % 6);
// Setup initial state to match menu selections
DefineContentState(c);
// Setup the correct starting colors to match the menu selections
DefineControlColors(c);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -