实例介绍
【实例简介】
一套黑色主题重绘控件
【实例截图】
【核心代码】
using DarkUI.Docking;
using DarkUI.Forms;
using DarkUI.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
namespace Example
{
public partial class MainForm : DarkForm
{
#region Field Region
private List<DarkDockContent> _toolWindows = new List<DarkDockContent>();
private DockProject _dockProject;
private DockProperties _dockProperties;
private DockConsole _dockConsole;
private DockLayers _dockLayers;
private DockHistory _dockHistory;
#endregion
#region Constructor Region
public MainForm()
{
InitializeComponent();
// Add the control scroll message filter to re-route all mousewheel events
// to the control the user is currently hovering over with their cursor.
Application.AddMessageFilter(new ControlScrollFilter());
// Add the dock content drag message filter to handle moving dock content around.
Application.AddMessageFilter(DockPanel.DockContentDragFilter);
// Add the dock panel message filter to filter through for dock panel splitter
// input before letting events pass through to the rest of the application.
Application.AddMessageFilter(DockPanel.DockResizeFilter);
// Hook in all the UI events manually for clarity.
HookEvents();
// Build the tool windows and add them to the dock panel
_dockProject = new DockProject();
_dockProperties = new DockProperties();
_dockConsole = new DockConsole();
_dockLayers = new DockLayers();
_dockHistory = new DockHistory();
// Add the tool windows to a list
_toolWindows.Add(_dockProject);
_toolWindows.Add(_dockProperties);
_toolWindows.Add(_dockConsole);
_toolWindows.Add(_dockLayers);
_toolWindows.Add(_dockHistory);
// Deserialize if a previous state is stored
if (File.Exists("dockpanel.config"))
{
DeserializeDockPanel("dockpanel.config");
}
else
{
// Add the tool window list contents to the dock panel
foreach (var toolWindow in _toolWindows)
DockPanel.AddContent(toolWindow);
// Add the history panel to the layer panel group
DockPanel.AddContent(_dockHistory, _dockLayers.DockGroup);
}
// Check window menu items which are contained in the dock panel
BuildWindowMenu();
// Add dummy documents to the main document area of the dock panel
DockPanel.AddContent(new DockDocument("Document 1", Icons.document_16xLG));
DockPanel.AddContent(new DockDocument("Document 2", Icons.document_16xLG));
DockPanel.AddContent(new DockDocument("Document 3", Icons.document_16xLG));
}
#endregion
#region Method Region
private void HookEvents()
{
FormClosing = MainForm_FormClosing;
DockPanel.ContentAdded = DockPanel_ContentAdded;
DockPanel.ContentRemoved = DockPanel_ContentRemoved;
mnuNewFile.Click = NewFile_Click;
mnuClose.Click = Close_Click;
btnNewFile.Click = NewFile_Click;
mnuDialog.Click = Dialog_Click;
mnuProject.Click = Project_Click;
mnuProperties.Click = Properties_Click;
mnuConsole.Click = Console_Click;
mnuLayers.Click = Layers_Click;
mnuHistory.Click = History_Click;
mnuAbout.Click = About_Click;
}
private void ToggleToolWindow(DarkToolWindow toolWindow)
{
if (toolWindow.DockPanel == null)
DockPanel.AddContent(toolWindow);
else
DockPanel.RemoveContent(toolWindow);
}
private void BuildWindowMenu()
{
mnuProject.Checked = DockPanel.ContainsContent(_dockProject);
mnuProperties.Checked = DockPanel.ContainsContent(_dockProperties);
mnuConsole.Checked = DockPanel.ContainsContent(_dockConsole);
mnuLayers.Checked = DockPanel.Contains(_dockLayers);
mnuHistory.Checked = DockPanel.Contains(_dockHistory);
}
#endregion
#region Event Handler Region
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
SerializeDockPanel("dockpanel.config");
}
private void DockPanel_ContentAdded(object sender, DockContentEventArgs e)
{
if (_toolWindows.Contains(e.Content))
BuildWindowMenu();
}
private void DockPanel_ContentRemoved(object sender, DockContentEventArgs e)
{
if (_toolWindows.Contains(e.Content))
BuildWindowMenu();
}
private void NewFile_Click(object sender, EventArgs e)
{
var newFile = new DockDocument("New document", Icons.document_16xLG);
DockPanel.AddContent(newFile);
}
private void Close_Click(object sender, EventArgs e)
{
Close();
}
private void Dialog_Click(object sender, EventArgs e)
{
var test = new DialogControls();
test.ShowDialog();
}
private void Project_Click(object sender, EventArgs e)
{
ToggleToolWindow(_dockProject);
}
private void Properties_Click(object sender, EventArgs e)
{
ToggleToolWindow(_dockProperties);
}
private void Console_Click(object sender, EventArgs e)
{
ToggleToolWindow(_dockConsole);
}
private void Layers_Click(object sender, EventArgs e)
{
ToggleToolWindow(_dockLayers);
}
private void History_Click(object sender, EventArgs e)
{
ToggleToolWindow(_dockHistory);
}
private void About_Click(object sender, EventArgs e)
{
var about = new DialogAbout();
about.ShowDialog();
}
#endregion
#region Serialization Region
private void SerializeDockPanel(string path)
{
var state = DockPanel.GetDockPanelState();
SerializerHelper.Serialize(state, path);
}
private void DeserializeDockPanel(string path)
{
var state = SerializerHelper.Deserialize<DockPanelState>(path);
DockPanel.RestoreDockPanelState(state, GetContentBySerializationKey);
}
private DarkDockContent GetContentBySerializationKey(string key)
{
foreach (var window in _toolWindows)
{
if (window.SerializationKey == key)
return window;
}
return null;
}
#endregion
}
}
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论