syncfusion-winforms-docking-manager
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplementing Syncfusion WinForms Docking Manager
实现Syncfusion WinForms Docking Manager
The DockingManager control implements an architecture that allows panels to be docked at any part of form, creating Visual Studio-style dockable windows. Dock panels can be interactively dragged, resized, floated, auto-hidden, tabbed, and arranged in complex layouts at runtime.
DockingManager控件实现了一套架构,允许面板停靠在窗体的任意位置,创建Visual Studio风格的可停靠窗口。停靠面板可在运行时被交互拖拽、调整大小、浮动、自动隐藏、标签化,以及排列为复杂布局。
When to Use This Skill
何时使用本指南
Use this skill when you need to:
- Create Visual Studio-style docking layouts with dockable panels and windows
- Implement multiple dock states: docked, floating, auto-hide, tabbed, MDI, or TDI windows
- Build document-based applications with TDI (Tabbed Document Interface) or MDI (Multiple Document Interface)
- Add caption buttons (close, pin, menu, maximize) to docked windows
- Persist dock layouts across application sessions using serialization
- Handle dock events for activation, state changes, and user interactions
- Customize appearance with visual styles, themes, and colors
- Manage nested or linked docking managers for complex layouts
- Implement drag-and-drop docking with visual feedback and hints
当你需要实现以下需求时可使用本指南:
- 打造Visual Studio风格的停靠布局,包含可停靠面板和窗口
- 实现多种停靠状态:停靠、浮动、自动隐藏、标签化、MDI或TDI窗口
- 构建基于文档的应用,支持TDI(标签式文档界面)或MDI(多文档界面)
- 为停靠窗口添加标题栏按钮(关闭、固定、菜单、最大化)
- 通过序列化功能跨应用会话持久化停靠布局
- 处理停靠相关事件,包括激活、状态变更和用户交互
- 自定义外观,支持视觉样式、主题和颜色配置
- 管理嵌套或关联的停靠管理器,实现复杂布局
- 实现拖拽停靠功能,附带视觉反馈和提示
Component Overview
组件概览
DockingManager transforms any control into a fully-featured docking window with:
- Dock States: Docked (Left, Right, Top, Bottom), Floating, Auto-Hide, Tabbed, Fill
- Document Windows: TDI (Tabbed Documents) and MDI (Multiple Documents)
- Caption Buttons: Close, Pin (Auto-Hide), Menu, Maximize, Restore, and custom buttons
- Visual Styles: Metro, Office2016 (Colorful, White, DarkGray, Black), VS2010, Office2007/2010
- Serialization: Save/load dock state to XML, binary, memory stream, or isolated storage
- Events: 25+ events for dock state changes, activation, dragging, context menus
- Advanced Features: Nested managers, linked managers, dock restrictions, tab groups
DockingManager可将任意控件转换为功能完整的停靠窗口,具备以下能力:
- 停靠状态:停靠(左、右、上、下)、浮动、自动隐藏、标签化、填充
- 文档窗口:TDI(标签式文档)和MDI(多文档)
- 标题栏按钮:关闭、固定(自动隐藏)、菜单、最大化、还原以及自定义按钮
- 视觉样式:Metro、Office2016(多彩、白色、深灰、黑色)、VS2010、Office2007/2010
- 序列化:支持将停靠状态保存/加载到XML、二进制文件、内存流或独立存储中
- 事件:提供25+个事件,覆盖停靠状态变更、激活、拖拽、上下文菜单等场景
- 高级特性:嵌套管理器、关联管理器、停靠限制、标签组
Documentation and Navigation Guide
文档与导航指南
Getting Started
入门指南
📄 Read: references/getting-started.md
- Installation and assembly deployment
- Creating DockingManager instance
- Adding dock child windows with SetEnableDocking
- Setting dock labels and icons
- Basic docking setup and configuration
📄 阅读: references/getting-started.md
- 安装与程序集部署
- 创建DockingManager实例
- 通过SetEnableDocking添加停靠子窗口
- 设置停靠标签与图标
- 基础停靠设置与配置
Dock States and Layouts
停靠状态与布局
📄 Read: references/dock-states.md
- Dock state overview (Docked, Float, Auto-Hide, Tabbed, Fill)
- DockControl function to change states programmatically
- Setting dock sides (Left, Right, Top, Bottom, Tabbed)
- Detecting and managing dock states
- Dock ability restrictions
📄 阅读: references/dock-states.md
- 停靠状态概览(停靠、浮动、自动隐藏、标签化、填充)
- 通过DockControl函数以编程方式修改状态
- 设置停靠方向(左、右、上、下、标签化)
- 检测与管理停靠状态
- 停靠能力限制
Document Windows (TDI/MDI)
文档窗口(TDI/MDI)
📄 Read: references/document-windows.md
- TDI (Tabbed Document Interface) implementation
- MDI (Multiple Document Interface) setup
- EnableDocumentMode property
- DockAsDocument function for adding document tabs
- Window modes (Tool vs Document behavior)
- Creating and managing document tab groups
- Freezing document state
📄 阅读: references/document-windows.md
- TDI(标签式文档界面)实现
- MDI(多文档界面)配置
- EnableDocumentMode属性
- 通过DockAsDocument函数添加文档标签
- 窗口模式(工具行为 vs 文档行为)
- 创建与管理文档标签组
- 冻结文档状态
Caption Buttons and Customization
标题栏按钮与自定义
📄 Read: references/caption-buttons.md
- Default caption buttons (Close, Pin, Menu, Maximize, Restore)
- Show/hide specific buttons with Set/Get functions
- Adding custom caption buttons to CaptionButtons collection
- Button click handling and events
- Customizing button appearance and colors
- Button tooltips and SuperTooltips
📄 阅读: references/caption-buttons.md
- 默认标题栏按钮(关闭、固定、菜单、最大化、还原)
- 通过Set/Get函数显示/隐藏指定按钮
- 向CaptionButtons集合添加自定义标题栏按钮
- 按钮点击处理与事件
- 自定义按钮外观与颜色
- 按钮工具提示与SuperTooltips
Floating Windows
浮动窗口
📄 Read: references/floating-windows.md
- Creating floating windows with FloatControl
- Floating by user drag interaction
- Enabling/disabling float functionality
- Floating window properties (border, size, location)
- Maximize floating windows
- Float-only windows (prevent re-docking)
- Show custom buttons in floating state
📄 阅读: references/floating-windows.md
- 通过FloatControl创建浮动窗口
- 用户拖拽交互实现浮动
- 启用/禁用浮动功能
- 浮动窗口属性(边框、大小、位置)
- 最大化浮动窗口
- 仅浮动窗口(禁止重新停靠)
- 在浮动状态下显示自定义按钮
Auto-Hide Windows
自动隐藏窗口
📄 Read: references/auto-hide-windows.md
- Auto-hide functionality overview
- SetAutoHideMode function
- Auto-hide programmatically or by user pin button
- Changing auto-hide side with DockControlInAutoHideMode
- Auto-hide on load with SetAutoHideOnLoad
- Animation settings and speed
- Auto-hide tab customization
- Auto-hide selection style (MouseHover vs Click)
📄 阅读: references/auto-hide-windows.md
- 自动隐藏功能概览
- SetAutoHideMode函数
- 以编程方式或通过用户点击固定按钮实现自动隐藏
- 通过DockControlInAutoHideMode修改自动隐藏停靠方向
- 通过SetAutoHideOnLoad实现加载时自动隐藏
- 动画设置与速度配置
- 自动隐藏标签自定义
- 自动隐藏选中样式(鼠标悬停 vs 点击)
Tabbed Windows
标签化窗口
📄 Read: references/tabbed-windows.md
- Tabbing windows together with Tabbed dock style
- Creating tab groups at design time and runtime
- Tab alignment options (Top, Bottom, Left, Right)
- Tab reordering with AllowTabsMoving
- Preventing tabbing with DockAbility
- Tab position management with Set/GetTabPosition
- Tab scroll buttons
📄 阅读: references/tabbed-windows.md
- 通过标签化停靠样式将窗口合并为标签组
- 在设计时和运行时创建标签组
- 标签对齐选项(上、下、左、右)
- 通过AllowTabsMoving启用标签拖拽重排
- 通过DockAbility禁止标签化
- 通过Set/GetTabPosition管理标签位置
- 标签滚动按钮
Appearance and Visual Styles
外观与视觉样式
📄 Read: references/appearance-customization.md
- Visual styles (Default, Metro, Office2016, VS2010, Office2007/2010)
- Office color schemes (Blue, Silver, Black, Managed)
- Custom colors for Office2007/2010
- Caption customization (background, foreground, font)
- Border colors and splitter customization
- Dock tab appearance (colors, fonts, height)
- Document tab styling
- Auto-hide tab styling
- Drag provider styles (VS2005, VS2008, VS2010, VS2012, Office2016)
- Right-to-left support
📄 阅读: references/appearance-customization.md
- 视觉样式(默认、Metro、Office2016、VS2010、Office2007/2010)
- Office配色方案(蓝色、银色、黑色、托管)
- Office2007/2010自定义颜色
- 标题栏自定义(背景、前景、字体)
- 边框颜色与分割线自定义
- 停靠标签外观(颜色、字体、高度)
- 文档标签样式
- 自动隐藏标签样式
- 拖拽提示样式(VS2005、VS2008、VS2010、VS2012、Office2016)
- 从右到左布局支持
Serialization and State Persistence
序列化与状态持久化
📄 Read: references/serialization.md
- Auto serialization with PersistState property
- SaveDockState and LoadDockState functions
- Serialize to XML file
- Serialize to binary file
- Serialize to memory stream for database storage
- Serialize to isolated storage
- Serialize specific controls only
- Restore to designer initial state
📄 阅读: references/serialization.md
- 通过PersistState属性实现自动序列化
- SaveDockState与LoadDockState函数
- 序列化到XML文件
- 序列化到二进制文件
- 序列化到内存流用于数据库存储
- 序列化到独立存储
- 仅序列化指定控件
- 恢复到设计器初始状态
Docking Events
停靠事件
📄 Read: references/docking-events.md
- DockControlActivated and DockControlDeactivated
- DockStateChanged and DockStateChanging
- AutoHideAnimationStart and AutoHideAnimationStop
- DragAllow, DragFeedbackStart, DragFeedbackStop
- DockContextMenu and AutoHideTabContextMenu
- ControlMaximizing, Maximized, Restored, Minimized
- DockVisibilityChanged and DockVisibilityChanging
- NewDockStateBeginLoad and NewDockStateEndLoad
- PreviewDockHints for restricting dock sides
- TabGroupCreating and TabGroupCreated
- TransferredToManager and TransferringFromManager
📄 阅读: references/docking-events.md
- DockControlActivated与DockControlDeactivated
- DockStateChanged与DockStateChanging
- AutoHideAnimationStart与AutoHideAnimationStop
- DragAllow、DragFeedbackStart、DragFeedbackStop
- DockContextMenu与AutoHideTabContextMenu
- ControlMaximizing、Maximized、Restored、Minimized
- DockVisibilityChanged与DockVisibilityChanging
- NewDockStateBeginLoad与NewDockStateEndLoad
- 用于限制停靠方向的PreviewDockHints
- TabGroupCreating与TabGroupCreated
- TransferredToManager与TransferringFromManager
Advanced Features
高级特性
📄 Read: references/advanced-features.md
- Nested docking managers (child manager within parent)
- Linked managers (drag between managers)
- Dock ability restrictions (SetDockAbility, SetOuterDockAbility)
- Size constraints (minimum size, freeze resizing)
- Prevent closing and docking operations
- Context menu customization (add/remove items)
- Splitter width and color customization
- Design-time docking features
- Localization support
📄 阅读: references/advanced-features.md
- 嵌套停靠管理器(父管理器内的子管理器)
- 关联管理器(跨管理器拖拽)
- 停靠能力限制(SetDockAbility、SetOuterDockAbility)
- 尺寸约束(最小尺寸、冻结调整大小)
- 禁止关闭与停靠操作
- 上下文菜单自定义(添加/移除选项)
- 分割线宽度与颜色自定义
- 设计时停靠特性
- 本地化支持
Quick Start Example
快速入门示例
Basic Docking Setup
基础停靠配置
csharp
using Syncfusion.Windows.Forms.Tools;
public partial class Form1 : Form
{
private DockingManager dockingManager1;
private Panel solutionExplorer;
private Panel toolbox;
private Panel properties;
private Panel output;
public Form1()
{
InitializeComponent();
// Create DockingManager
this.dockingManager1 = new DockingManager(this.components);
this.dockingManager1.HostControl = this;
// Create dock panels
this.solutionExplorer = new Panel();
this.toolbox = new Panel();
this.properties = new Panel();
this.output = new Panel();
// Add panels to form
this.Controls.AddRange(new Control[] {
solutionExplorer, toolbox, properties, output
});
// Enable docking for all panels
this.dockingManager1.SetEnableDocking(solutionExplorer, true);
this.dockingManager1.SetEnableDocking(toolbox, true);
this.dockingManager1.SetEnableDocking(properties, true);
this.dockingManager1.SetEnableDocking(output, true);
// Set dock labels
this.dockingManager1.SetDockLabel(solutionExplorer, "Solution Explorer");
this.dockingManager1.SetDockLabel(toolbox, "Toolbox");
this.dockingManager1.SetDockLabel(properties, "Properties");
this.dockingManager1.SetDockLabel(output, "Output");
// Arrange dock positions
this.dockingManager1.DockControl(solutionExplorer, this, DockingStyle.Right, 250);
this.dockingManager1.DockControl(toolbox, this, DockingStyle.Left, 200);
this.dockingManager1.DockControl(properties, solutionExplorer, DockingStyle.Tabbed, 200);
this.dockingManager1.DockControl(output, this, DockingStyle.Bottom, 150);
// Apply visual style
this.dockingManager1.VisualStyle = VisualStyle.Office2016Colorful;
}
}csharp
using Syncfusion.Windows.Forms.Tools;
public partial class Form1 : Form
{
private DockingManager dockingManager1;
private Panel solutionExplorer;
private Panel toolbox;
private Panel properties;
private Panel output;
public Form1()
{
InitializeComponent();
// 创建DockingManager
this.dockingManager1 = new DockingManager(this.components);
this.dockingManager1.HostControl = this;
// 创建停靠面板
this.solutionExplorer = new Panel();
this.toolbox = new Panel();
this.properties = new Panel();
this.output = new Panel();
// 向窗体添加面板
this.Controls.AddRange(new Control[] {
solutionExplorer, toolbox, properties, output
});
// 为所有面板启用停靠能力
this.dockingManager1.SetEnableDocking(solutionExplorer, true);
this.dockingManager1.SetEnableDocking(toolbox, true);
this.dockingManager1.SetEnableDocking(properties, true);
this.dockingManager1.SetEnableDocking(output, true);
// 设置停靠标签
this.dockingManager1.SetDockLabel(solutionExplorer, "Solution Explorer");
this.dockingManager1.SetDockLabel(toolbox, "Toolbox");
this.dockingManager1.SetDockLabel(properties, "Properties");
this.dockingManager1.SetDockLabel(output, "Output");
// 排列停靠位置
this.dockingManager1.DockControl(solutionExplorer, this, DockingStyle.Right, 250);
this.dockingManager1.DockControl(toolbox, this, DockingStyle.Left, 200);
this.dockingManager1.DockControl(properties, solutionExplorer, DockingStyle.Tabbed, 200);
this.dockingManager1.DockControl(output, this, DockingStyle.Bottom, 150);
// 应用视觉样式
this.dockingManager1.VisualStyle = VisualStyle.Office2016Colorful;
}
}Common Patterns
常用模式
Creating Document Windows (TDI)
创建文档窗口(TDI)
csharp
// Enable document mode
this.dockingManager1.EnableDocumentMode = true;
// Add document tabs in NewDockStateEndLoad event
this.dockingManager1.NewDockStateEndLoad += (s, e) =>
{
this.dockingManager1.DockAsDocument(document1);
this.dockingManager1.DockAsDocument(document2);
};
// Set window mode (Tool allows dock/float, Document allows float only)
this.dockingManager1.SetWindowMode(document1, WindowMode.Document);csharp
// 启用文档模式
this.dockingManager1.EnableDocumentMode = true;
// 在NewDockStateEndLoad事件中添加文档标签
this.dockingManager1.NewDockStateEndLoad += (s, e) =>
{
this.dockingManager1.DockAsDocument(document1);
this.dockingManager1.DockAsDocument(document2);
};
// 设置窗口模式(Tool允许停靠/浮动,Document仅允许浮动)
this.dockingManager1.SetWindowMode(document1, WindowMode.Document);Changing Dock States Programmatically
以编程方式修改停靠状态
csharp
// Dock a control to specific side
this.dockingManager1.DockControl(panel1, this, DockingStyle.Left, 200);
// Float a control at specific location
Rectangle bounds = new Rectangle(100, 100, 300, 400);
this.dockingManager1.FloatControl(panel1, bounds);
// Auto-hide a control
this.dockingManager1.SetAutoHideMode(panel1, true);
// Tab control with another
this.dockingManager1.DockControl(panel2, panel1, DockingStyle.Tabbed, 200);csharp
// 将控件停靠到指定方向
this.dockingManager1.DockControl(panel1, this, DockingStyle.Left, 200);
// 在指定位置浮动控件
Rectangle bounds = new Rectangle(100, 100, 300, 400);
this.dockingManager1.FloatControl(panel1, bounds);
// 为控件启用自动隐藏
this.dockingManager1.SetAutoHideMode(panel1, true);
// 将控件与另一个控件合并为标签组
this.dockingManager1.DockControl(panel2, panel1, DockingStyle.Tabbed, 200);Customizing Caption Buttons
自定义标题栏按钮
csharp
// Hide close button for specific control
this.dockingManager1.SetCloseButtonVisibility(panel1, false);
// Hide pin (auto-hide) button
this.dockingManager1.SetAutoHideButtonVisibility(panel1, false);
// Add custom caption button
CaptionButton customBtn = new CaptionButton();
customBtn.Name = "CustomButton";
customBtn.ImageIndex = 3; // From ImageList
customBtn.Type = CaptionButtonType.Custom;
this.dockingManager1.CaptionButtons.Add(customBtn);
// Customize button colors
this.dockingManager1.ActiveCaptionButtonForeColor = Color.Red;
this.dockingManager1.InActiveCaptionButtonForeColor = Color.Gray;csharp
// 隐藏指定控件的关闭按钮
this.dockingManager1.SetCloseButtonVisibility(panel1, false);
// 隐藏固定(自动隐藏)按钮
this.dockingManager1.SetAutoHideButtonVisibility(panel1, false);
// 添加自定义标题栏按钮
CaptionButton customBtn = new CaptionButton();
customBtn.Name = "CustomButton";
customBtn.ImageIndex = 3; // 来自ImageList
customBtn.Type = CaptionButtonType.Custom;
this.dockingManager1.CaptionButtons.Add(customBtn);
// 自定义按钮颜色
this.dockingManager1.ActiveCaptionButtonForeColor = Color.Red;
this.dockingManager1.InActiveCaptionButtonForeColor = Color.Gray;Serialization (Save/Load Layout)
序列化(保存/加载布局)
csharp
using Syncfusion.Runtime.Serialization;
// Enable auto-save on close
this.dockingManager1.PersistState = true;
// Save to XML file manually
AppStateSerializer serializer = new AppStateSerializer(
SerializeMode.XMLFile, "DockLayout");
this.dockingManager1.SaveDockState(serializer);
serializer.PersistNow();
// Load from XML file
AppStateSerializer serializer = new AppStateSerializer(
SerializeMode.XMLFile, "DockLayout");
this.dockingManager1.LoadDockState(serializer);
// Save to memory stream (for database)
MemoryStream ms = new MemoryStream();
AppStateSerializer serializer = new AppStateSerializer(
SerializeMode.BinaryFmtStream, ms);
this.dockingManager1.SaveDockState(serializer);
serializer.PersistNow();
// Store ms.ToArray() in databasecsharp
using Syncfusion.Runtime.Serialization;
// 启用关闭时自动保存
this.dockingManager1.PersistState = true;
// 手动保存到XML文件
AppStateSerializer serializer = new AppStateSerializer(
SerializeMode.XMLFile, "DockLayout");
this.dockingManager1.SaveDockState(serializer);
serializer.PersistNow();
// 从XML文件加载
AppStateSerializer serializer = new AppStateSerializer(
SerializeMode.XMLFile, "DockLayout");
this.dockingManager1.LoadDockState(serializer);
// 保存到内存流(用于数据库存储)
MemoryStream ms = new MemoryStream();
AppStateSerializer serializer = new AppStateSerializer(
SerializeMode.BinaryFmtStream, ms);
this.dockingManager1.SaveDockState(serializer);
serializer.PersistNow();
// 将ms.ToArray()存储到数据库Handling Dock Events
处理停靠事件
csharp
// Track dock state changes
this.dockingManager1.DockStateChanged += (s, e) =>
{
foreach (Control ctrl in e.Controls)
{
Console.WriteLine($"{ctrl.Name} state changed");
}
};
// Prevent specific dock operations
this.dockingManager1.DockStateChanging += (s, e) =>
{
if (e.NewState == DockState.Float && e.Controls[0] == panel1)
{
e.Cancel = true; // Prevent panel1 from floating
}
};
// Handle control activation
this.dockingManager1.DockControlActivated += (s, e) =>
{
Console.WriteLine($"{e.Control.Name} activated");
};
// Restrict dock sides dynamically
this.dockingManager1.PreviewDockHints += (s, e) =>
{
if (e.DraggingTarget == panel2)
{
// Only allow right docking on panel2
e.DockAbility = DockAbility.Right;
}
};csharp
// 跟踪停靠状态变更
this.dockingManager1.DockStateChanged += (s, e) =>
{
foreach (Control ctrl in e.Controls)
{
Console.WriteLine($"{ctrl.Name} state changed");
}
};
// 阻止特定停靠操作
this.dockingManager1.DockStateChanging += (s, e) =>
{
if (e.NewState == DockState.Float && e.Controls[0] == panel1)
{
e.Cancel = true; // 禁止panel1浮动
}
};
// 处理控件激活事件
this.dockingManager1.DockControlActivated += (s, e) =>
{
Console.WriteLine($"{e.Control.Name} activated");
};
// 动态限制停靠方向
this.dockingManager1.PreviewDockHints += (s, e) =>
{
if (e.DraggingTarget == panel2)
{
// 仅允许panel2停靠在右侧
e.DockAbility = DockAbility.Right;
}
};Restricting Dock Abilities
限制停靠能力
csharp
// Restrict where control can dock (inner docking)
this.dockingManager1.SetDockAbility(panel1, DockAbility.Top | DockAbility.Bottom);
// Restrict where control can dock in client area (outer docking)
this.dockingManager1.SetOuterDockAbility(panel1,
DockAbility.Left | DockAbility.Right);
// Make control float-only (cannot re-dock)
this.dockingManager1.SetFloatOnly(panel1, true);
// Disable floating for specific control
this.dockingManager1.SetAllowFloating(panel1, false);csharp
// 限制控件的内部停靠方向
this.dockingManager1.SetDockAbility(panel1, DockAbility.Top | DockAbility.Bottom);
// 限制控件在客户区的外部停靠方向
this.dockingManager1.SetOuterDockAbility(panel1,
DockAbility.Left | DockAbility.Right);
// 设为仅浮动模式(无法重新停靠)
this.dockingManager1.SetFloatOnly(panel1, true);
// 禁用指定控件的浮动能力
this.dockingManager1.SetAllowFloating(panel1, false);Customizing Appearance
自定义外观
csharp
// Set visual style
this.dockingManager1.VisualStyle = VisualStyle.Office2016Colorful;
// Customize active caption colors
this.dockingManager1.ActiveCaptionBackground = new BrushInfo(
GradientStyle.Horizontal, Color.DarkBlue, Color.LightBlue);
this.dockingManager1.ActiveCaptionForeGround = Color.White;
// Customize dock tab colors
this.dockingManager1.DockTabBackColor = Color.LightGray;
this.dockingManager1.ActiveDockTabBackColor = Color.White;
this.dockingManager1.DockTabForeColor = Color.Black;
// Customize document tab colors
this.dockingManager1.DocumentWindowSettings.TabBackColor = Color.SteelBlue;
this.dockingManager1.DocumentWindowSettings.ActiveTabBackColor = Color.Green;
this.dockingManager1.DocumentWindowSettings.TabHeight = 38;
// Set drag provider style
this.dockingManager1.DragProviderStyle = DragProviderStyle.VS2012;csharp
// 设置视觉样式
this.dockingManager1.VisualStyle = VisualStyle.Office2016Colorful;
// 自定义激活状态标题栏颜色
this.dockingManager1.ActiveCaptionBackground = new BrushInfo(
GradientStyle.Horizontal, Color.DarkBlue, Color.LightBlue);
this.dockingManager1.ActiveCaptionForeGround = Color.White;
// 自定义停靠标签颜色
this.dockingManager1.DockTabBackColor = Color.LightGray;
this.dockingManager1.ActiveDockTabBackColor = Color.White;
this.dockingManager1.DockTabForeColor = Color.Black;
// 自定义文档标签颜色
this.dockingManager1.DocumentWindowSettings.TabBackColor = Color.SteelBlue;
this.dockingManager1.DocumentWindowSettings.ActiveTabBackColor = Color.Green;
this.dockingManager1.DocumentWindowSettings.TabHeight = 38;
// 设置拖拽提示样式
this.dockingManager1.DragProviderStyle = DragProviderStyle.VS2012;Key Properties and Methods
核心属性与方法
Essential Properties
关键属性
- HostControl: Gets/sets the parent control hosting the docking layout
- EnableDocumentMode: Enable TDI (Tabbed Document Interface) mode
- PersistState: Enable automatic save/load of dock state
- VisualStyle: Set appearance theme (Metro, Office2016, VS2010, etc.)
- DragProviderStyle: Set drag hint style (VS2005, VS2008, VS2010, VS2012)
- AutoHideEnabled: Enable/disable auto-hide (pin) functionality
- AllowTabsMoving: Enable tab reordering by drag-and-drop
- ShowCaption: Show/hide caption bar for all dock windows
- CaptionButtons: Collection of caption buttons (Close, Pin, Menu, etc.)
- HostControl:获取/设置承载停靠布局的父控件
- EnableDocumentMode:启用TDI(标签式文档界面)模式
- PersistState:启用停靠状态的自动保存/加载
- VisualStyle:设置外观主题(Metro、Office2016、VS2010等)
- DragProviderStyle:设置拖拽提示样式(VS2005、VS2008、VS2010、VS2012)
- AutoHideEnabled:启用/禁用自动隐藏(固定)功能
- AllowTabsMoving:启用通过拖拽重排标签
- ShowCaption:显示/隐藏所有停靠窗口的标题栏
- CaptionButtons:标题栏按钮集合(关闭、固定、菜单等)
Essential Methods
关键方法
Adding Dock Children:
- : Enable docking for a control
SetEnableDocking(Control, bool) - : Set caption label text
SetDockLabel(Control, string) - : Set caption icon
SetDockIcon(Control, Icon)
Changing Dock States:
- : Dock control at specific side
DockControl(Control, Control, DockingStyle, int) - : Float control at location
FloatControl(Control, Rectangle) - : Set auto-hide state
SetAutoHideMode(Control, bool) - : Convert to MDI child window
SetAsMDIChild(Control, bool) - : Add as TDI document tab
DockAsDocument(Control)
State Management:
- : Get current dock style
GetDockStyle(Control) - : Check if control is floating
IsFloating(Control) - : Check if control is auto-hidden
GetAutoHideMode(Control) - : Check if control is MDI child
IsMDIMode(Control) - : Check if control is tabbed
IsTabbed(Control)
Serialization:
- : Save to isolated storage
SaveDockState() - : Save to file/stream
SaveDockState(AppStateSerializer) - : Load from isolated storage
LoadDockState() - : Load from file/stream
LoadDockState(AppStateSerializer)
Caption Buttons:
- : Show/hide close button
SetCloseButtonVisibility(Control, bool) - : Show/hide pin button
SetAutoHideButtonVisibility(Control, bool) - : Show/hide menu button
SetMenuButtonVisibility(Control, bool)
Restrictions:
- : Restrict inner docking sides
SetDockAbility(Control, DockAbility) - : Restrict outer docking sides
SetOuterDockAbility(Control, DockAbility) - : Make control float-only
SetFloatOnly(Control, bool) - : Enable/disable floating
SetAllowFloating(Control, bool)
添加停靠子元素:
- :为控件启用停靠能力
SetEnableDocking(Control, bool) - :设置标题栏标签文本
SetDockLabel(Control, string) - :设置标题栏图标
SetDockIcon(Control, Icon)
修改停靠状态:
- :将控件停靠到指定方向
DockControl(Control, Control, DockingStyle, int) - :在指定位置浮动控件
FloatControl(Control, Rectangle) - :设置自动隐藏状态
SetAutoHideMode(Control, bool) - :转换为MDI子窗口
SetAsMDIChild(Control, bool) - :添加为TDI文档标签
DockAsDocument(Control)
状态管理:
- :获取当前停靠样式
GetDockStyle(Control) - :检查控件是否处于浮动状态
IsFloating(Control) - :检查控件是否处于自动隐藏状态
GetAutoHideMode(Control) - :检查控件是否为MDI子元素
IsMDIMode(Control) - :检查控件是否被标签化
IsTabbed(Control)
序列化:
- :保存到独立存储
SaveDockState() - :保存到文件/流
SaveDockState(AppStateSerializer) - :从独立存储加载
LoadDockState() - :从文件/流加载
LoadDockState(AppStateSerializer)
标题栏按钮:
- :显示/隐藏关闭按钮
SetCloseButtonVisibility(Control, bool) - :显示/隐藏固定按钮
SetAutoHideButtonVisibility(Control, bool) - :显示/隐藏菜单按钮
SetMenuButtonVisibility(Control, bool)
权限限制:
- :限制内部停靠方向
SetDockAbility(Control, DockAbility) - :限制外部停靠方向
SetOuterDockAbility(Control, DockAbility) - :设为仅浮动模式
SetFloatOnly(Control, bool) - :启用/禁用浮动能力
SetAllowFloating(Control, bool)
Common Use Cases
常见使用场景
1. Visual Studio-Style IDE Layout
1. Visual Studio风格IDE布局
Create solution explorer, toolbox, properties, and output windows with docking, floating, and auto-hide capabilities.
创建解决方案资源管理器、工具箱、属性面板、输出窗口,支持停靠、浮动和自动隐藏能力。
2. Document Editing Application
2. 文档编辑应用
Implement tabbed document interface (TDI) for multiple document editing with tool windows around the edges.
实现标签式文档界面(TDI),支持多文档编辑,边缘分布工具窗口。
3. Dashboard Layout Manager
3. 仪表盘布局管理器
Build customizable dashboard with dockable widget panels that users can arrange and persist.
构建可自定义的仪表盘,包含可停靠的组件面板,用户可自行排列并持久化布局。
4. Multi-Panel Data Viewer
4. 多面板数据查看器
Display multiple data grids, charts, and details panels with flexible docking and tabbing.
展示多个数据网格、图表和详情面板,支持灵活的停靠和标签化布局。
5. Application with Persistent Layout
5. 带持久化布局的应用
Save and restore user's preferred window arrangement across sessions using serialization.
通过序列化功能跨会话保存和恢复用户偏好的窗口排列。
6. MDI Application Modernization
6. MDI应用现代化改造
Convert traditional MDI applications to modern docking interface with floating and tabbed documents.
将传统MDI应用升级为现代化停靠界面,支持浮动和标签化文档。
7. Custom Development Tools
7. 自定义开发工具
Build code editors, debuggers, or design tools with dockable windows similar to Visual Studio.
构建类似Visual Studio的代码编辑器、调试器或设计工具,附带可停靠窗口。